如何在没有ajax的情况下将javascript动态数据发送到php变量
how to send javascript dynamic data to php variable without ajax
我有一个表单,有3个输入类型的文本。
<input type="text" id="one" onkeyup="multiply()" name="one">
<input type="text" id="two" name="two">
<input type="text" id="three" name="three">
<script>
function multiply(){
one = document.getElementById('one').value;
two = document.getElementById('two').value;
document.getElementById('three').value = one * two
}
</script>
现在我没有三个值,但它是动态的,当我将论坛提交到(forumSubmit.php)时,我会得到的错误
undefiend index three
我搜索了&发现这可以用ajax完成,但我不想使用ajax,我想做一个页面刷新
您可以这样做:
标记
<!-- Use onkeyup on both inputs -->
<input type="text" id="one" onkeyup="multiply()" name="one">
<input type="text" id="two" onkeyup="multiply()" name="two">
<input type="text" id="three" name="three">
JavaScript
function multiply() {
// Parse the values, and count it as 0 if the input is not a number
// I also made the variables private to this function using the var keyword
// There is no need to have them in the global namespace
var one = parseInt(document.getElementById('one').value, 10) || 0;
var two = parseInt(document.getElementById('two').value, 10) || 0;
document.getElementById('three').value= one * two;
}
工作示例
制作一个演示:http://jsfiddle.net/DjQNx/
<input type="text" id="one" onkeyup="multiply()" name="one" />
<input type="text" id="two" onkeyup="multiply()" name="two" />
<input type="text" id="three" name="three" />
<script type="text/javascript">
function multiply() {
one = document.getElementById('one').value;
two = document.getElementById('two').value;
document.getElementById('three').value = one * two;
}
</script>
相关文章:
- 下载使用POST数据动态生成的文件
- 使用enyo.js将数据动态插入表中
- (Laravel)使用数据库中的数据动态打开模态
- 如何根据数据动态创建引导下拉列表
- 将json数据动态加载到D3节点中
- 如何在 React 中将 html 表单元格数据动态插入到具有动态标题的表中
- 使用数据库返回的数据动态填充下拉列表
- 从 JSON 数据动态创建 Jquery 移动导航栏
- 将数据动态发送到服务器
- 如何通过角度 ui-grid 中来自$scope的数据动态设置指令
- 如何在 ASP.NET 中将数据动态追加到 JQuery 控件变量
- 用于流程图的 JavaScript 绘图库,并将数据动态附加到视图
- 使用Angular ng-repeat将数据动态加载到materializecss滑块中不起作用
- 在 Laravel 5.1 和 Vue JS 中保存多个数据动态表单
- 当没有提供json数据的结构/字段名称时,将json数据动态显示为表
- 如何使用entityframwork和sql数据动态显示jqgrid数据
- Javascript:如何从字符串数据动态构建方法
- Javascript:将数据动态添加到数组中
- Ember数据动态模型未加载到存储中
- 使用JSON URL数据动态填充HTML表