•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 391,596 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,706 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 9686 | Replies: 9
![]() |
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
<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
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:
<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
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:
Rep Power: 3
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>>>
<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)
<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)
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb HTML and CSS Marketplace
- Previous Thread: The new "haslayout" IE CSS feature - Explained
- Next Thread: Onclick questions



Linear Mode