topical media & game development

talk show tell print

basic-web-html-12-ch12-eg05.htm / htm



  <html>
  <head>
  <title>The test() method</title>
  <script type="text/JavaScript">
  
  function validate(form) {
  
  var returnValue = true;
  var amountEntered = document.frmCurrency.txtAmount.value;
  var currencyFormat = /^\d+(\.\d{1,2})?/;
  
  if (!currencyFormat.test(amountEntered))
  {
  alert("You did not enter an amount of money");
  document.frmCurrency.txtAmount.focus();
  returnValue = false;
  }
    
  return returnValue;
  }
  </script>
  </head>
  <body>
  <form name="frmCurrency" onsubmit="return validate(this);" action="money.aspx" method="get">
  
  Enter an amount of money here  <input type="text" name="txtAmount" id="txtAmount" size="7" />
  <input type="submit" value="Check format" />
  
  </form>
  
  </body>
  </html>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.