简体   繁体   English

如何将javascript变量值分配给文本框 - 在PHP中

[英]how to assign the javascript variable value to textbox - in PHP

I am trying to display some javascript variable on my html page. 我想在我的html页面上显示一些javascript变量。

var resultDis = 10;
document.getElementById("totalAmount").value= resultDis; 

using 运用

<input type="number" id="totalAmount" name="totalAmount" 
class="form-control" ng-model="form.totalAmount" 
placeholder="Total Amount" value="">

Here totalAmount : id of text those i want assign the value 这里totalAmount:我希望分配值的文本的id

But on the form submission, null value goes of that textbox. 但是在表单提交上,该值为该文本框的空值。

id="totalAmount"添加到文本框中。

<input id="totalAmount" ...> 

As you have in your input ng-model="form.totalAmount" you can update the value with AngularJS: 正如您在输入ng-model="form.totalAmount"您可以使用AngularJS更新值:

 angular .module('MyApp', []) .controller('MyController', function($scope) { var resultDis = 10; $scope.form = {}; // value assignment to form.totalAmount model $scope.form.totalAmount = resultDis; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="MyApp" ng-controller="MyController"> <input type="number" id="totalAmount" name="totalAmount" class="form-control" ng-model="form.totalAmount" placeholder="Total Amount" value=""> </div> 

Note that now the input will show the variable resultDis value on the view.. But, how are you handling the form submit? 请注意 ,现在输入将在视图上显示变量resultDis值。但是,您如何处理表单提交? Can you update your question with more code? 你能用更多代码更新你的问题吗?

如果您在Visual Studio中工作,则必须使用ClientID:

var resultDis = 10; document.getElementById("<%=totalAmount.ClientID%>").value= resultDis;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM