A how-to code example from ASPFree. <html> <head> <title>Form Validation Using JavaScript</title> <script LANGUAGE="JavaScript"> <!-- Hides Code function validateIt() //function is called when the button is clicked { var dblNum; var txtText; var txtMessage; dblNum = 0.1; if(!isNaN(document.form1.txtNum.value)) /* document.[form name].[field name].value Checks to see if it is a number (isNaN: Not a Number) */ { dblNum = document.form1.txtNum.value; /* alerts display message boxes */ } else { alert("Field must contain a number"); document.form1.txtNum.focus(); return; } txtText = document.form1.txtText.value; if(!isNaN(document.form1.txtText.value)) { alert("Requires text, and not a number"); document.form1.txtText.focus(); return; } if(txtText.length < 8) /* checks to see if the lenght of the text field is greater than 8 */ { alert("Text must be at least 8 letters long"); document.form1.txtText.focus(); return; } if(dblNum < 250.55) /* makes sure that the number entered meets the criteria */ { alert("Number must be greater than 250.55") document.form1.txtNum.focus(); return; } alert("Everything Checks Out Fine") return; } //--> </script> </head> <body background="../images/aspfreebkgrnd.gif"> <p>How to validate a form entry using javascript:</p> <form method="POST" name="form1" action="javaform.asp" webbot-action="--WEBBOT-SELF--"> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" width="44%"> <tr> <td width="41%">Text of 8 letters: </td> <td width="59%"><input type="text" name="txtText" size="20"></td> </tr> <tr> <td width="41%">Number > 250.55</td> <td width="59%"><input type="text" name="txtNum" size="20"></td> </tr> <tr> <td width="41%" colspan="2"> <p align="center"><input type="button" value="Button" name="B1" onClick="validateIt();"></td></tr> </table> </center> </div> </form> </body> </html> | DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Windows Scripting Articles More By Steve Schofield developerWorks - FREE Tools! | Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
| | | | Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
| | | | Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
| | | | Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
| | | | Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |