Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how I would do the basic validation using <a href="http://jquery.com/" rel="nofollow">jQuery</a>.</p> <pre><code>$(document).ready(function(){ $('#contact').keypress(function(e){ //when user presses a key in that Input Box var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) // check if it is Enter Key { if($(this).val().trim().length == 0) // check if it is empty alert("Error: Shouldn't be empty !"); else { // You are good to go here } } }); });​ </code></pre> <p>HTML:</p> <pre><code>&lt;input id="contact" name="contact" value="" /&gt;​ </code></pre> <p>If you wish to test it live, goto: <a href="http://jsfiddle.net/NFSTL/" rel="nofollow">http://jsfiddle.net/NFSTL/</a></p> <p>I binded the <a href="http://api.jquery.com/keypress/" rel="nofollow">KeyPress</a> event to that InputBox.</p> <p>Hope it helps. :)</p> <hr> <p><strong>EDIT</strong></p> <p>Without using jQuery:</p> <pre><code>function ajaxFunction(e){ var code; if (!e) var e = window.event; if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) // defeat Safari bug targ = targ.parentNode; if(code==13) { if(targ.value.trim().length == 0) alert("Error: This shouldn't be empty!"); else { //do the sending and receiving of data here... } } }​ </code></pre> <p>HTML:</p> <pre><code>&lt;input id="agid" type="text" name="contactid" onkeyup="ajaxFunction(event)" /&gt;​ </code></pre> <p>For live testing: <a href="http://jsfiddle.net/SYf4C/" rel="nofollow">http://jsfiddle.net/SYf4C/</a></p> <p>Here's an excellent tutorial I used: <a href="http://www.quirksmode.org/js/events_properties.html" rel="nofollow">quirksmode.org/js/events_properties</a></p> <p>I would say that, jQuery makes life easier. :) Because it is a JavaScript library composed to work in almost all browsers.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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