更新java脚本中的表单字段 [英] updating form fields in java script

查看:67
本文介绍了更新java脚本中的表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用java脚本更新隐藏字段,而我只是从我的选择中获取其中一个值的
。以下是代码

.

< select name =" on0">

< option value =" 25" > 25

< option value =" 50"> 50

< / select>

< script language =" ; javascript">

document.write(''< input type =" hidden" name =" amount"'');

if(document。 test.on0.options [document.test.on0.selectedIndex] .value

== 50)

document.write(''value =" 275"'' );

else

document.write(''value =" 250"'');


document.write (''>'');


< / script>


无论我做什么,金额的价值都是总是250 ...任何想法

在这里?


Aaron

I''m trying to update a hidden field with java script and I''m only
getting one of the values from my select stament. Here is the code
below.
<select name="on0">
<option value="25">25
<option value="50">50
</select>
<script language="javascript">
document.write(''<input type="hidden" name="amount"'');
if (document.test.on0.options[document.test.on0.selectedIndex].value
== 50)
document.write(''value="275"'');
else
document.write(''value="250"'');

document.write(''>'');

</script>

No matter what I do the value of "amount" is always 250... any ideas
here?

Aaron

推荐答案

我们************** *@gmail.com 说:

>
我正在尝试使用java脚本更新隐藏字段而且我''我只能从我的选择中获得一个价值观。以下是代码

< select name =" on0">
< option value =" 25"> 25
< option value = " 50" 50
< / select>
< script language =" javascript">
document.write(''< input type =" hidden" name =" amount"'');
if(document.test.on0.options [document.test.on0.selectedIndex] .value
== 50)
document.write( ''value =" 275"'');
其他
document.write(''value =" 250"'');

document.write(' '>'');

< / script>

无论我做什么,金额的价值都是总是250 ......任何想法
在这里?
>
I''m trying to update a hidden field with java script and I''m only
getting one of the values from my select stament. Here is the code
below.
<select name="on0">
<option value="25">25
<option value="50">50
</select>
<script language="javascript">
document.write(''<input type="hidden" name="amount"'');
if (document.test.on0.options[document.test.on0.selectedIndex].value
== 50)
document.write(''value="275"'');
else
document.write(''value="250"'');

document.write(''>'');

</script>

No matter what I do the value of "amount" is always 250... any ideas
here?



当页面加载时,包含document.write()行的代码块只执行一次

。在做出选择时,它不会更新值




如果您希望在选择时更新document.test.amount.value

,你需要在< selecttag上添加一个onchange处理程序。

如果你只想在表单提交时更新它,你就可以了应该

为< formtag添加一个onsubmit处理程序。

-

The block of code that contains the document.write() lines is only
executed once, as the page is loading. It won''t update the value
when a selection is made.

If you want document.test.amount.value to be updated when a selection
is made, you''ll need to add an onchange handler to the <selecttag.
If you only want it to be updated as your form is submitted, you should
add an onsubmit handler to the <formtag.
--


在执行时间,表格选择'的价值是25.


你要找的是这样的......


< input type =" hidden"名称= QUOT;量QUOT; ID = QUOT;量QUOT;值= QUOT;" />

< select id =" on0"名称= QUOT; ON0" onchange =''alertInput()''>

< option value =" 25"> 25< / option>

< option value =" 50"> 50< / option>

< / select>

< script>


function alertInput() {$ / $

var selID = document.getElementById(''on0'');


document.getElementById(''amount'')。 value =

parseInt(
At the time of execution, the form select''s value is 25.

What you are looking for is something such as this....

<input type="hidden" name="amount" id="amount" value="" />
<select id="on0" name="on0" onchange=''alertInput()''>
<option value="25">25</option>
<option value="50">50</option>
</select>
<script>

function alertInput(){

var selID = document.getElementById(''on0'');

document.getElementById(''amount'').value =
parseInt(


(selID).options
(selID).options


这篇关于更新java脚本中的表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆