-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.

vaibhav shah
  • 4,939
  • 19
  • 58
  • 96
  • possible duplicate of [**Check if textbox has empty value**](http://stackoverflow.com/questions/1565193/check-if-textbox-has-empty-value) or [**check if text box is empty then run code**](http://stackoverflow.com/questions/7350676/check-if-text-box-is-empty-then-run-code) In addition you are asking to solve 3 issues. You should add some of [**the code you have tried**](http://whathaveyoutried.com) to address the 3 issues when asking for assistance in finding a solution. – Nope May 22 '13 at 21:09

3 Answers3

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");
                }
            }
        }
    });
Alex
  • 9,911
  • 5
  • 33
  • 52
0
var val = $('#textbox').val();

if (val) {
    //Do whatever...
}
Jared
  • 2,978
  • 4
  • 26
  • 45
0

Trim the input value before checking length:

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