-2

I have one jquery dialog in my app.

Here Is how It is made

    var routePopup = "Route Name : <input type='text' id='routeName' name='routeName'/>";


    document.getElementById('popUp').innerHTML = "";
    document.getElementById('popUp').innerHTML = routePopup;

    $("#popUp").dialog({
        title: "Route Name",
        resizable: false,
        width: auto,
        height: auto,
        buttons: {
            "Create Route": function () {
                $(this).dialog("close");
            }
        }
    });

now I want to check if textbox is empty or not. If it is empty then it should not allow to close the popup.

Also It should give message on top that the value can not be empty.

1

3 Answers 3

2

Why are you writing document.getElementById('popUp').innerHTML = ""; if you could do $('#popUp').html(''); - that's why you use jQuery :)

$("#popUp").dialog({
        title: "Route Name",
        resizable: false,
        width: auto,
        height: auto,
        buttons: {
            "Create Route": function () {
                if ($(this).val() == '') {
                    alert('May not be empty!');
                }
                else {
                    $(this).dialog("close");
                }
            }
        }
    });
Sign up to request clarification or add additional context in comments.

2 Comments

I also want to give message on top to user if textbox is empty.
see updated answer. it uses alert() but you can do anything else
0
var val = $('#textbox').val();

if (val) {
    //Do whatever...
}

Comments

0

Trim the input value before checking length:

if ( $("#txt").val().trim().length == 0 )
{
    // do something
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.