DynamicCustomFormValidation.html
******************************
<script type="text/javascript" src="../jquery-1.6.2.js"></script>
<script type="text/javascript" src="../jquery.validate.js"></script>
<script>
$(document).ready(function() {
$("#form2").submit(function()
{
var selError="";
$("[id^=sport]").each(function()
{
//resetting the Color of Both checkbox,when clicked 2nd times onwards
$(this).css({'background-color':'white'});
if($(this).val()=="none")
{
selError+=$(this).attr("id");
$(this).css({'background-color':'wheat'});
}//if
});//for each
if(selError.length!=0)
{
$("#showmsg").html(selError);
$("#showmsg").css({'background-color':'wheat'});
return false;//stop page from being submitted
}
else return true;//submit the page
});//submit()
}); //onready()
</script>
<body>
<form id="form2">
<select name="sport1" id="sport1">
<option value="none">Select a sport</option>
<option value="baseball">Baseball</option>
<option value="basketball">Basketball</option>
<option value="soccer">Soccer</option>
<option value="football">Football</option>
</select> <br>
<select name="sport2" id="sport2">
<option value="none">Select a sport</option>
<option value="cricket">cricket</option>
<option value="badminton">badminton</option>
<option value="swimming">swimming</option>
<option value="volleyball">VolleyBall</option>
</select>
<br>
<input type="submit" value="Submit" id="submitBtn">
</form>
<div id="showmsg" width=200></div>
</body>
*********************************Ends********************************************
******************************
<script type="text/javascript" src="../jquery-1.6.2.js"></script>
<script type="text/javascript" src="../jquery.validate.js"></script>
<script>
$(document).ready(function() {
$("#form2").submit(function()
{
var selError="";
$("[id^=sport]").each(function()
{
//resetting the Color of Both checkbox,when clicked 2nd times onwards
$(this).css({'background-color':'white'});
if($(this).val()=="none")
{
selError+=$(this).attr("id");
$(this).css({'background-color':'wheat'});
}//if
});//for each
if(selError.length!=0)
{
$("#showmsg").html(selError);
$("#showmsg").css({'background-color':'wheat'});
return false;//stop page from being submitted
}
else return true;//submit the page
});//submit()
}); //onready()
</script>
<body>
<form id="form2">
<select name="sport1" id="sport1">
<option value="none">Select a sport</option>
<option value="baseball">Baseball</option>
<option value="basketball">Basketball</option>
<option value="soccer">Soccer</option>
<option value="football">Football</option>
</select> <br>
<select name="sport2" id="sport2">
<option value="none">Select a sport</option>
<option value="cricket">cricket</option>
<option value="badminton">badminton</option>
<option value="swimming">swimming</option>
<option value="volleyball">VolleyBall</option>
</select>
<br>
<input type="submit" value="Submit" id="submitBtn">
</form>
<div id="showmsg" width=200></div>
</body>
*********************************Ends********************************************
No comments:
Post a Comment