You are currently viewing the BOOK: Beginning Java Script section of the Wrox Programmer to Programmer discussions.
This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. I have a form which contains a text box in which the user will input employee numbers.
When I copied and pasted your code into a html file and ran it, my FF and IE spat out an error.
If you put an alert() inside and just below your IF block I think you'll find the alert() inside the IF block will never be executed, hence your form is always submitted whether you check any boxes or not.
i just want to declare these functions and pass the textboxes to them as required.
the following is the java script code for validating function . You have to use get Element By Id to get a handle on the box (you can use it indirectly via j Query, but let's not get pedantic), the issue is if you use get get Element By Id and pass the result to your function, or pass just the id to your function and use get Element By Id inside the function itself.
Using regular expressions the entered content can be validated with advanced conditions like the string entered shouldn’t contain spaces, special characters, numbers, uppercase or lowercase etc.
From numbers we’ll move to alphabets first an example for validation lowercase alphabets and then to validate both uppercase and lowercase.