如何使用 javascript 更改表单的输入值
如何根据所选的女巫组合框项目使用 javascript 更改表单的输入值。我有一个包含一些导入值的表单,并且有一个可以通过组合框更改女巫导入值的字段。就我而言:
print("<input type='hidden' name='issue_array[{$issue["nr"]}][\"supplier\"]' value='{$issue["supplier"]}' />");
我有一个组合框,如果我更改它的值,应该更改上面输入的值。
这是我尝试过的:
print("<select name='supplier_combo' onchange='setSupplierInputValue(this.value, ${issue['nr']})'>");
和脚本:
echo "\r\n" . '<SCRIPT TYPE="text/javascript">' . "\r\n";
echo 'function setSupplierInputValue(value, issue_nr)' . "\r\n";
echo '{' . "\r\n";
echo ' issue_array[issue_nr]["supplier"] = value;';
echo '}' . "\r\n";
echo '</SCRIPT>'. "\r\n";
但它不起作用,请帮忙。
How can I change a form's input value with javascript depending on witch combobox item is selected. I have a form with some imported values, and there is a field of witch imported value can be changed via a combobox. In my case:
print("<input type='hidden' name='issue_array[{$issue["nr"]}][\"supplier\"]' value='{$issue["supplier"]}' />");
I have a combobox, that if I change it's value, should change the value of the input above.
This is what I tried:
print("<select name='supplier_combo' onchange='setSupplierInputValue(this.value, ${issue['nr']})'>");
and the script:
echo "\r\n" . '<SCRIPT TYPE="text/javascript">' . "\r\n";
echo 'function setSupplierInputValue(value, issue_nr)' . "\r\n";
echo '{' . "\r\n";
echo ' issue_array[issue_nr]["supplier"] = value;';
echo '}' . "\r\n";
echo '</SCRIPT>'. "\r\n";
But it doesn't work, please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给组合框一个id,例如选择和输入的id,比如inputExample,所以使用jquery你可以
我希望它有帮助。您还可以在 jquery 网站上查看参考: http://api.jquery.com/change/
give the combobox an id for example selection and id for the input say inputExample, so using jquery you can
I hope it helps. You can also see the reference on jquery site : http://api.jquery.com/change/
将您的行更改
为如下所示(您必须使用
getElementsByName
选择隐藏字段 - 或为隐藏字段设置 id 并使用getElementById
):change your line
to look like this (you have to select the hidden field by using
getElementsByName
- or set an id for the hidden field and usegetElementById
):