动态改变表格价值 [英] Dynamically changing form value
问题描述
我想基于输入更改表格中输入字段的值 提交表单之前,其中一个字段没有刷新就可以保存.
I would like to change the value of input fields in a form based on the input of one of the fields live without refresh before submitting the form.
例如
<input type="text" name="chance" value="50">
比方说,用户在该字段中输入80.
Let's say a user inputs 80 into the field.
然后我将能够进行1/输入x 98的计算,其中输入= 80(所以它将是1/80 x 98).
Would I then be able to do the calculation 1/input x 98 where the input = 80 (so it would be 1/80 x 98).
然后将其设置为表单中另一个字段的输入值.
I would then set this as the value of input of another field in the form.
<input type="text" name="payout" value="1/input x 98">
不刷新页面. TIA
Without refreshing the page. TIA
推荐答案
在更改chance
时,您可以像这样设置payout
的值.
On change of chance
you can set the value of payout
like this.
<input type="text" name="chance" value="50"
onchange="document.getElementById('payout').value='1/'+this.value+'x 98'">
如果您想随时随地进行而无需回车,请使用
If you want on that on the go without need of enter then use
<input type="text" name="chance" value="50"
onkeyup="document.getElementById('payout').value='1/'+this.value+'x 98'">
Chance: <input type="text" name="chance" value=""
onkeyup="document.querySelector('input[name=payout]').value=this.value?1/this.value*98:''">
<br/><br/>Payout: <input type="text" name="payout" value=""><br/>
If you want to restrict the chance field to enter only number then check out this link
这篇关于动态改变表格价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!