Reputation: 8249
Currently I'm using simple javascript alert box to validate my input. Now I want to change it to be jQuery Alert Dialogs
I'm trying something like this, but doesn't work.
Javascript:
function validation() {
str = document.step;
if (str.full_name.value == "") {
jAlert('Please enter this field', 'Alert Dialog');
//alert('Please enter this field');
str.full_name.focus();
return false;
}
}
HTML:
<form action="" method="post" id="step" name="step" onsubmit="return validation();">
<input type="text" id="full_name" name="full_name" />
<input type="submit" name="submit" value="Submit" />
</form>
Let me know
Upvotes: 0
Views: 462
Reputation: 359936
You're using jQuery, so there's no reason to not write unobtrusive JavaScript.
<form action="" method="post" id="step">
<input id="full_name" name="full_name" />
<input type="submit" name="submit" value="Submit" />
</form>
$(function ()
{
var $fullName = $('#full_name');
$('#step').submit(function ()
{
if (!$fullName.val())
{
jAlert('Please enter this field', 'Alert Dialog');
$fullName.focus();
return false;
}
});
});
Make sure that your page includes all of the dependencies:
Upvotes: 2