How do I replace current alert() in javascript to be jQuery Alert Dialogs plugin
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
You're using jQuery, so there's no reason to not write unobtrusive JavaScript.
HTML
<form action="" method="post" id="step">
<input id="full_name" name="full_name" />
<input type="submit" name="submit" value="Submit" />
</form>
JavaScript
$(function ()
{
var $fullName = $('#full_name');
$('#step').submit(function ()
{
if (!$fullName.val())
{
jAlert('Please enter this field', 'Alert Dialog');
$fullName.focus();
return false;
}
});
});
Demo
Make sure that your page includes all of the dependencies:
- jQuery JS
- jQuery UI draggable JS
- jAlert JS and CSS
精彩评论