检查下拉列表中的值是否与文本框中输入的值匹配 [英] check if value in drop down list match value entered in textbox
本文介绍了检查下拉列表中的值是否与文本框中输入的值匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含2个文本框(用户名和密码)和1个下拉列表的登录表单,用于选择用户类型(学生或讲师)。
我为讲师输入正确的用户名和密码我在下拉列表中选择讲师。
我希望在javascript中获得此验证的代码。
I have a login form with 2 textboxes (username & password) and 1 drop down list to choose the type of user (student or lecturer).
I enter the correct username and password for lecturer and I select "lecturer" in the drop down list.
I want to have the codes for this validation in javascript.
推荐答案
您好,
以下是您可以使用的工作代码
HTML部分:
Hi,
Here is the working code you can make use of
HTML Part:
<input type="text" id="txtLoginType"/>
<select id="ddlloginType" onchange="return validate();">
<option>Select</option>
<option>lecturer</option>
<option>student</option>
</select>
Javascript Part:
Javascript Part:
function validate()
{
var content = document.getElementById('txtLoginType');
var dropdownType = document.getElementById('ddlloginType');
if (content.value == dropdownType.options[dropdownType.selectedIndex].value)
{
alert('Valid');
//Doo your valid function
}
else
{
alert('Invalid');
//Doo your Invalid function
}
}
希望这对你有所帮助。
问候,
RK
Hope this helps you a bit.
Regards,
RK
这篇关于检查下拉列表中的值是否与文本框中输入的值匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文