wow
wow

Reputation: 8249

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

Upvotes: 0

Views: 462

Answers (1)

Matt Ball
Matt Ball

Reputation: 359936

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:

Upvotes: 2

Related Questions