Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 25-Feb-14 19:27pm
v2
Comments
♥…ЯҠ…♥ 26-Feb-14 1:49am    
Want code for validating dropdownlist alone? to match with the string lecturer or student right?

1 solution

Hi,

Here is the working code you can make use of

HTML Part:
HTML
<input type="text" id="txtLoginType"/>
  <select id="ddlloginType" onchange="return validate();">
    <option>Select</option>
    <option>lecturer</option>
    <option>student</option>
  </select>

Javascript Part:
JavaScript
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
  }
}


Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
Comments
Member 10626057 27-Feb-14 0:53am    
thx RK..
but whatever option i select i got the "invalid" message..
♥…ЯҠ…♥ 27-Feb-14 23:08pm    
Content.value is the content you need to check it, and it should not be empty also

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900