Note that there are some explanatory texts on larger screens.

plurals
  1. POPass return from JQuery Function to Another Function?
    primarykey
    data
    text
    <p>I am working on a form validator and when I call the function submitcheck at the bottom the if condition isn't being met and the <code>$("#send").button("enable");</code> isn't firing. I've confirmed without the if statement that the function does get called and if <code>$("#send").button("enable");</code> fires it works as intended. What am I doing wrong here?</p> <pre><code> function submitcheck() { if (firstnamecheck() &amp; lastnamecheck() &amp; phonenumbercheck() &amp; emailaddresscheck() &amp; customermessagecheck() == true) { $("#send").button("enable"); } } $(".email").click(function() { $("#email-form").dialog("open"); }); $("#first-name").keyup(function(firstnamecheck) { if ($("#first-name").val().length &gt;= 2) { $("#first-name-check").fadeIn(100); return true; } else if ($("#first-name").val().length &lt; 2) { $("#first-name-check").fadeOut(100); return false; } }); $("#last-name").keyup(function(lastnamecheck) { if ($("#last-name").val().length &gt;= 2) { $("#last-name-check").fadeIn(100); return true; } else if ($("#last-name").val().length &lt; 2) { $("#last-name-check").fadeOut(100); return false; } }); $("#area-code, #phone-prefix, #phone-postfix").keyup(function(phonenumbercheck) { if ((($("#area-code").val().length == 3) &amp;&amp; ($("#phone-prefix").val().length == 3) &amp;&amp; ($("#phone-postfix").val().length == 4))) { $("#phone-number-check").fadeIn(100); return true; } else if ((($("#area-code").val().length &lt; 3) &amp;&amp; ($("#phone-prefix").val().length &lt; 3) &amp;&amp; ($("#phone-postfix").val().length &lt; 4))) { $("#phone-number-check").fadeOut(100); return false; } }); $("#email-address").keyup(function(emailaddresscheck) { if ($("#email-address").val().length &gt;= 6) { $("#email-address-check").fadeIn(100); return true; } else if ($("#email-address").val().length &lt;= 5) { $("#email-address-check").fadeOut(100); return false; } }); $("#customer-message").keyup(function(customermessagecheck) { if ($("#customer-message").val().length &gt;= 10) { $("#customer-message-check").fadeIn(100); return true; } else if ($("#customer-message").val().length &lt;= 9) { $("#customer-message-check").fadeOut(100); return false; } }); $("#customer-message").keyup(submitcheck); </code></pre> <p>OK thanks to you guys I got it figured out. I rewrote the script so it has separate handler functions and seperate activators. The following DOES work:</p> <pre><code> function submitcheck() { if (firstnamecheck() &amp;&amp; lastnamecheck() &amp;&amp; phonenumbercheck() &amp;&amp; emailaddresscheck() &amp;&amp; customermessagecheck() === true) { $("#send").button("enable"); } } function firstnamecheck() { if ($("#first-name").val().length &gt;= 2) { $("#first-name-check").fadeIn(100); return true; } else if ($("#first-name").val().length &lt; 2) { $("#first-name-check").fadeOut(100); return false; } } function lastnamecheck() { if ($("#last-name").val().length &gt;= 2) { $("#last-name-check").fadeIn(100); return true; } else if ($("#last-name").val().length &lt; 2) { $("#last-name-check").fadeOut(100); return false; } } function phonenumbercheck() { if ((($("#area-code").val().length == 3) &amp;&amp; ($("#phone-prefix").val().length == 3) &amp;&amp; ($("#phone-postfix").val().length == 4))) { $("#phone-number-check").fadeIn(100); return true; } else if ((($("#area-code").val().length &lt; 3) &amp;&amp; ($("#phone-prefix").val().length &lt; 3) &amp;&amp; ($("#phone-postfix").val().length &lt; 4))) { $("#phone-number-check").fadeOut(100); return false; } } function emailaddresscheck() { if ($("#email-address").val().length &gt;= 6) { $("#email-address-check").fadeIn(100); return true; } else if ($("#email-address").val().length &lt;= 5) { $("#email-address-check").fadeOut(100); return false; } } function customermessagecheck() { if ($("#customer-message").val().length &gt;= 10) { $("#customer-message-check").fadeIn(100); return true; } else if ($("#customer-message").val().length &lt;= 9) { $("#customer-message-check").fadeOut(100); return false; } } $(".email").click(function() { $("#email-form").dialog("open"); }); $("#first-name").keyup(firstnamecheck); $("#last-name").keyup(lastnamecheck); $("#area-code, #phone-prefix, #phone-postfix").keyup(phonenumbercheck); $("#email-address").keyup(emailaddresscheck); $("#customer-message").keyup(customermessagecheck); $("#customer-message").keyup(submitcheck); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload