Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

I want to know how to write a java script to check if the text-boxes, dropdown list are empty or not. And if they are empty it should call a css class and display a message within that text box.
Posted
Comments
Vedangi 11-Jun-12 1:15am    
You want to display message in same textbox or in different textbox. ??
Sandeep Mewara 11-Jun-12 2:41am    
Did you try anything?

1 solution

Sample JavaScript to validate the text box is empty or not:
JavaScript
if (document.getElementById('txtName').value=='')
{}


dropdown list select is empty or not:
XML
<select>
<option selected value="123">123</option>
<option value="234">234</option>
</select>


JavaScript
var hasValue = ($('select > [selected]').length > 0);
 
Share this answer
 

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