You must Sign In to post a response.
  • Category: JQuery

    Jquery to validate textbox fields in the website.

    I have a popup or say a div having 6 text fields. I have got first textfield focused on load event. Now
    I want jquery code to attain following functionalities:

    1. On enter key or tab key press it should be checked if the textbox is empty, if so focus on the same
    textbox else move on the next text box.

    2. But on click event user can opt out for some other textbox (even if the current textbox is empty)

    3. The div has an Add button which initailly is disabled (which I ll take care of), and the Add button should
    get enabled only when all the fields are non empty.


    **One of the textfields will be email and on will be password. Please use jquery to validate email and
    also the password field should have functionalities 1 and 2.
    ** All the textbox fields have random ids.

    I need this solution today itself as i have to implement tommorow. Its urgent.


    Regards


    Dn
  • #758327
    On blur() event you can check if textbox is empty or not, see below snippet

    <form>

    <input id="target" type="text" value="Field 1">

    <input type="text" value="Field 2">

    </form>

    <div id="other">

    Trigger the handler

    </div>

    The event handler can be bound to the first input field:

    $('input, textarea').blur(function() {
    if ($(this).val() == "") alert("empty!");
    });

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #758329
    Hello Deepak,

    Refer the below code:
    <input type="text" name="checking" id="checking"
    onblur="checkTextField(this);" />

    function checkTextField(field) {
    if (field.value == '') {
    alert("Field is empty");
    }
    }

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."


  • Sign In to post your comments