选择onChange在表单内不起作用 [英] select onChange not working inside a form

查看:279
本文介绍了选择onChange在表单内不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对表单提交和问题有疑问. onchange事件无法协同工作.当我更改下拉列表上的值时,事件viewroom()不会触发.有人可以帮我吗?代码如下

I have a question about form submit & onchange events not working together. When I change the value on the dropdown list the event viewroom() is not firing. Could anyone help me with this? The code is as follows

<script type="text/javascript">
function viewroom()
{
    alert(123);
}
</script>

<form id="myform" name="myform" action="joinroom.php" method="post">
<select name="viewroom" id="viewroom" onChange="viewroom()">
    <option value="1">Room1 </option>
    <option value="2">Room2 </option>
</select>
<input type="submit" onclick="this.form.submit()" value="Join room"><br>
</form>

推荐答案

您的函数名称与selectnameid冲突,只需为函数指定另一个名称即可.

Your function name conflicts with name and id of the select, just give another name to the function.

这篇关于选择onChange在表单内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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