Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In answer to your questions...</p> <ol> <li>The keydown or keypress events can be intercepted before text is input using javascript</li> <li>You can return false after binding a function to the keydown or keypress event. This will prevent the text from being input.</li> </ol> <p><strong>Example using jQuery:</strong></p> <pre><code>$("#inputfield").live("keydown", function(){ return false; }); </code></pre> <p>If you want to test some input for value on form submit you can do that using jQuery <a href="http://docs.jquery.com/Events/submit" rel="nofollow noreferrer">submit()</a>.</p> <pre><code>$("#theform").submit(function() { var formval = $("#theinput").val(); if(formval == "") { //or some better test alert("input value"); //or some other alert... return false; } else { return true; } }); </code></pre> <p>Returning false will invalidate the click to submit the form.</p> <p><strong>Edit:</strong> If as you say in your comments you want to disable the submission of the form until requirements are met for the input field(s)</p> <pre><code>$("#inputfield").live("keyup", function(){ if($("#inputfield").val() == "") { $('#button').attr("disabled", true); } else { $('#button').attr("disabled", false); } }); </code></pre> <p>You want to use the "<a href="http://docs.jquery.com/Events/keyup" rel="nofollow noreferrer">keyup</a>" event handler to allow the text to be sent first. see my example: <a href="http://jsbin.com/epavo/" rel="nofollow noreferrer">on jsbin</a> </p>
 

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