By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

validation script

P: 6
I need a validation script for a form to perform 2 actions:
1. if a checkbox is checked, then a relevant textfield should contain some input
2. don't allow commas (,) inside that textfield

Can anybody help me with this?
Nov 23 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Check the checked property of the checkbox. If checked, then check that the text field is not empty:
Expand|Select|Wrap|Line Numbers
  1. if (chkBox.checked) {
  2.   if (textField.value == "") {
  3.     // error...
To check for commas, you could use a regular expression or just indexOf().
Nov 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.