david
david

Reputation: 161

jquery ui dialog box always returning false

When u enter text into the input or not the dialog box opens. should only open if no value is found: fiddle = http://jsfiddle.net/tzxS2/

code/css/js: does not seem to work in a form:

 <form id="dacform" method='get' action='dac' onsubmit="return check_domain_input()" accept-charset='utf-8'>
    <input name='domain' type="text" style="font-size:15px;" class="searchbox"/>
    <select style="background:#f8f8f8; margin-left:4px; font-size:15px;" class="selectlist slight" id="selectdomain" name="tld">
      <option value=''>( all )</option>
      <option value="co.uk">co.uk</option>
      <option value="me.uk">me.uk</option>
      <option value="org.uk">org.uk</option>
      <option value="com">com</option>
    </select>
    <input onclick="check_domain_input()" class="btn grey bbig" name="search" type="submit" value="Search" style="width:59px; margin-left:7px; font-size:15px;" />
    </form><br />
    Our domain registration system is highly automated so we register your domain names fast and secure.

    <div id="dialog" title="Attention!" style="display:none">
    Please enter a domain name to search for.
    </div>
<div onclick="check_domain_input()">Click</div>

<div id="dialog" title="Attention!" style="display:none">
    Please enter a domain name to search for.
</div>

<script>
    function check_domain_input()
    {        
        $( "#dialog" ).dialog(); // Shows the new alert box.

        var domain_val = document.getElementsByName('domain');

        if (domain_val[0].value.length > 0)
        {
            return true;
        }

        $( "#dialog" ).dialog();

        return false;
    }
</script>

Upvotes: 0

Views: 284

Answers (2)

Rohit416
Rohit416

Reputation: 3486

according to your situation, you should not call your ui-dialog twice in your code.

try this..

<script>
function check_domain_input()
{        
var domain_val = document.getElementsByName('domain');

if (domain_val[0].value.length > 0)
  {
    return true;
  }

else
  {
    $( "#dialog" ).dialog();
    return false;
  }
}
</script>

Upvotes: 0

It seems to me that you are always opening the dialog with the first line of your function's body:

   $( "#dialog" ).dialog(); // Shows the new alert box.

regardless of the value of the input.

Try removing that line.

Upvotes: 1

Related Questions