You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Simon Meaden <si...@lineone.net> on 2002/09/17 23:58:20 UTC

html:text numerical only

Hi,
I looked in the archive and cant find an answer to this. I am trying to limit
an html:text box to numerical keypresses only ,using Javascript if there is
no better solution. I dont want to reload the page after every keypress.

I haven't used JavaScript or in fact struts much but I have this code.

<script language="JavaScript">
<!--
  // Times can only have numerical entries.
  function checkNumericalKey() {
    if ( event.keyCode < 48 || event.keyCode > 57 ) {
      alert( "Only numbers are allowed in this field!" );
      return false;
    } else {
      return true;
    }
  }
  document.
-->
</script>

called by this.

<html:text size="5" maxlength="5" property="monFromAM" tabindex="15"
onkeypress="checkNumericalKey();"/>

unfortunately it doesn't seem to even call the function. Any idea what I am
doing wrong.

Thanks in advance.
Simon Meaden

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>