| | |
how to validate checkbox with different names?
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
HI~
i have a series of checkbox with different names, how do i validate them? validate to check that one of the checkbox must be checked in order to save the changes in the current page.
here are my checkbox codings
thanks in advance..
i have a series of checkbox with different names, how do i validate them? validate to check that one of the checkbox must be checked in order to save the changes in the current page.
here are my checkbox codings
HTML and CSS Syntax (Toggle Plain Text)
<input type="checkbox" name="stud" value="yes">Student <input type="checkbox" name="lect" value="yes">Lecturer <input type="checkbox" name="principal" value="yes">Principal <input type="checkbox" name="admin" value="yes">Administrator <input type="checkbox" name="parent" value="yes">Parent
cheers,
ohgosh
ohgosh
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
I mean, if the user must pick one, but only one, of the checkboxes, then you should give them all the same name.
If you must give them a separate name, then you will have to inspect the ".checked" property of each checkbox in your validation function.
Do you know how to look at the ".checked" property of a checkbox?
If you must give them a separate name, then you will have to inspect the ".checked" property of each checkbox in your validation function.
Do you know how to look at the ".checked" property of a checkbox?
•
•
•
•
Originally Posted by tgreer
Do you know how to look at the ".checked" property of a checkbox?
do u all mean that besides validating at the client-side by using js, i will also need to validate at the server-side? but how to?
cheers,
ohgosh
ohgosh
btw.. i have another qn..
can i retrieve the break tag from querystring? i have a textarea which i store in a querystring. the textarea will not show the break tag if i have break tag among the text i typed.
let me explain in greater details. i have a dropdownlist whereby onclick it will store the values from other html inputs' values (textarea, dropdownlist) into the querystring, and the html inputs' values should remain. the problem is that if i have a chunk of words in a textarea where there are paragraph breaks and when the dropdownlist onclick triggers, there are no paragraph breaks, the words are all joined together.
here are my codes:
can i retrieve the break tag from querystring? i have a textarea which i store in a querystring. the textarea will not show the break tag if i have break tag among the text i typed.
let me explain in greater details. i have a dropdownlist whereby onclick it will store the values from other html inputs' values (textarea, dropdownlist) into the querystring, and the html inputs' values should remain. the problem is that if i have a chunk of words in a textarea where there are paragraph breaks and when the dropdownlist onclick triggers, there are no paragraph breaks, the words are all joined together.
here are my codes:
HTML and CSS Syntax (Toggle Plain Text)
<textarea name="txt" id="txt" rows="5" cols="100" class="text" mandatory='true' display='txt' pattern='ALPHA_NUMERIC_PLUS'><%=request.QueryString("txt")%></textarea> function check(){ document.form.action = "page.asp?txt="+document.form.txt.value; document.form.submit(); }
cheers,
ohgosh
ohgosh
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
Please post separate questions in a separate thread. Also, please don't use "chat shorthand" in forum messages. Rather, fully type out all words, and use proper spelling and punctuation. When seeking clarity, be clear!
Tell me exactly what it is about the checkbox situation that you want to "validate". First, are the checkboxes mutually exclusive? That is, are they part of a group of choices, and the user must pick one and only one of them?
Tell me exactly what it is about the checkbox situation that you want to "validate". First, are the checkboxes mutually exclusive? That is, are they part of a group of choices, and the user must pick one and only one of them?
•
•
Join Date: Aug 2005
Posts: 20
Reputation:
Solved Threads: 0
I think you mean mean it this way:
Before we process input from form we should validate it by using javascript. To validate checkboxes or any other elements of the form you should put return statement in the onSubmit statement>>>
validate() returns boolean value that tells the form to post input or not.
This was basics validation
To validate checkboxes you need to check value(checked or not)
----------------------------------
PS: you can use model document.formname.objectname.checked instead of document.forms[0].email but some netscape browsers will generate error
PS: document.forms[number].email- number is a number of the form on the page (starts form 0)
Before we process input from form we should validate it by using javascript. To validate checkboxes or any other elements of the form you should put return statement in the onSubmit statement>>>
HTML and CSS Syntax (Toggle Plain Text)
<script language=javascript> function validate(){ var email=document.forms[0].email.value; var comment=document.forms[0].comment.value; if(email==""||(email.indexOf('@')==-1)||(email.indexOf('.')==-1)){ alert("E-mail field is invalid!"); document.forms[0].email.focus(); return false; } if(comment==""){ alert("Comment field is empty!"); document.forms[0].comment.focus(); return false; } return true; } </script> <form name="contact_form" method="post" action="http://..." onSubmit="return validate()"> <br> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form>
validate() returns boolean value that tells the form to post input or not.
This was basics validation
To validate checkboxes you need to check value(checked or not)
HTML and CSS Syntax (Toggle Plain Text)
<script language=javascript> function validate(){ var email=document.forms[0].email; if(email.checked!=true){ alert("Email is not checked!"); return false; } return true; } </script>
----------------------------------
PS: you can use model document.formname.objectname.checked instead of document.forms[0].email but some netscape browsers will generate error
PS: document.forms[number].email- number is a number of the form on the page (starts form 0)
![]() |
Other Threads in the HTML and CSS Forum
- Previous Thread: The new "haslayout" IE CSS feature - Explained
- Next Thread: Onclick questions
Views: 12600 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for HTML and CSS
2002 appointments asp background backgroundcolor beta browser bug calendar cart center cgi code codeinjection corporateidentity create css deleted design development displayimageinsteadofflash dreamweaver drupal emailmarketing epilepsy explorer firefox flash font fonts form format free frontpage google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft missing mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization perl pnginie6 positioning problem scroll seo shopping studio swf swf. templates textcolor theme timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7 wordpress xml xsl






