admin管理员组文章数量:1403240
I have written the below code. But it does not show me the alert message when I don't select the other value and click onto the submit button.
I don't want to use getElementbyId
. I am using the name attribute of the HTML.
<HTML>
<HEAD>
<TITLE>ComboBox Validation</TITLE>
<script Language="JavaScript">
function validate()
{
if (documentboForm.technology.value=="0") \
{
alert("Please Select Technology");
}
}
</script>
</HEAD>
<BODY>
<form name="boForm">
<select name="technology">
<option value="0">Select</option>
<option value="1">Java Server Pages</option>
</select>
<input type="submit" value="submit" onClick="validate();">
</form>
</BODY>
</HTML>
I have written the below code. But it does not show me the alert message when I don't select the other value and click onto the submit button.
I don't want to use getElementbyId
. I am using the name attribute of the HTML.
<HTML>
<HEAD>
<TITLE>ComboBox Validation</TITLE>
<script Language="JavaScript">
function validate()
{
if (document.boForm.technology.value=="0") \
{
alert("Please Select Technology");
}
}
</script>
</HEAD>
<BODY>
<form name="boForm">
<select name="technology">
<option value="0">Select</option>
<option value="1">Java Server Pages</option>
</select>
<input type="submit" value="submit" onClick="validate();">
</form>
</BODY>
</HTML>
Share
Improve this question
edited Jan 23, 2012 at 17:21
Alex Turpin
47.8k23 gold badges116 silver badges146 bronze badges
asked Jan 23, 2012 at 17:17
user460920user460920
8875 gold badges17 silver badges27 bronze badges
3
- That isn't a bobox. It is a "Drop down menu". A bobox is a bination of a drop down menu and a text input (hence the name). – Quentin Commented Jan 23, 2012 at 17:19
- 1 Why don't you want to use IDs? That's the safest, most reliable, fastest way. That owuld be like writing HTML tags in all caps. Oh wait... – Alex Turpin Commented Jan 23, 2012 at 17:21
- ok..so how to validate the bobox then ?? – user460920 Commented Jan 23, 2012 at 17:30
1 Answer
Reset to default 3I think you want:
if (document.forms["boForm"].technology.value == "0")
But really, stop avoiding document.getElementById
. That's the clearest, easiest way to deal with this:
<select id="ddTechnology" name="technology">
<option value="0">Select</option>
<option value="1">Java Server Pages</option>
</select>
if (document.getElementById("ddTechnology").value == "0")
本文标签: validate combobox in javascriptStack Overflow
版权声明:本文标题:validate combobox in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744320724a2600481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论