JS Code:
<script type="text/javascript">
function validate() {
if($('#usr_name').val()==''){
alert('Enter Your Name!!!');
$('#usr_name').focus();
return false;
}
</script>
HTML code:
<div class="label_left"><label>Name :</label></div>
<div class="text_right">
<input type="text" name="usr_name" id="usr_name" value="" size="30" /><br /><br />
</div>
am using this format to validation in jquery. it is showing an alert message. but what i require is it has to place enter your name beside the label when it is not filled is it possible. if so how to do this. help me thanks.
search for jquery validation plugins, lot of them are available in net
Following is the source for jquery validation with example.
Create another div whose style contains display:none, beside/below/wherever the element you want to validate. If the validation fails, use jQuery's .show method to show the hidden warning. for example:
<script type="text/javascript">
function validate() {
if($('#usr_name').val()==''){
$("#name_warning_id").show();
$('#usr_name').focus();
return false;
}
</script>
<div class="label_left"><label>Name :</label></div>
<div class="text_right"><input type="text" name="usr_name" id="usr_name" value="" size="30" /><div class="some_warning_class" id="name_warning_id" style="display:none;background-color:#F4A83D">Enter Your Name</div><br /><br />
</div>