Click to See Complete Forum and Search --> : Radio button validatation
shyra_ann
03-09-2005, 03:28 PM
I feel silly for asking so many questions here. I'm just a bit confused.
I'm back again, sorry for so many posts. I am trying to validate my radio buttons. I know I should use an array but I can't figure arrays out. I've tried several ways and nothing works, my fault I know.
Can anyone give me standard array code that I can modify or learn from?
shyra_ann
03-09-2005, 04:30 PM
I found a code but it doesn't work. Can anyone see why?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Shannon Brossoit's Web Form</title>
<script type="text/javascript">
// this is for older Internet Explorers which don't understand getElementById:
if (document.all && !document.getElementById)
document.getElementById = function(id) {
return document.all[id];
}
function hideAll() {
for (formNumber=1; formNumber<=3; formNumber++)
document.getElementById("form"+formNumber).style.display = 'none';
}
function show(formNumber) {
document.getElementById("form"+formNumber).style.display = 'block';
}
function validate(form) {
if (form.FromAddress.value == '') {
alert ('Please fill in your email');
event.returnValue=false;
}
if(form.Name.value =='') {
alert ('Please give your name.');
event.returnValue=false;
}
if (form.zipcode.value =='') {
alert('Please enter your zip code.');
event.returnValue=false;
}
if(form.huh.value == '') {
alert ('Please give an explaination of your problem');
event.returnValue=false;
}
if(form.Country.value =='') {
alert ('Please fill in your country');
event.returnValue=false;
}
if(form.name == 'form3' && (!form3.contact.checked && !form3.contact2.checked)) {
alert('Please choose how you wish to be contacted.');
event.returnValue=false;
}
function process()
{
var
validationSucceed = false,
noRadioButtonChecked = true,
formHandle = document.forms[ 'form2' ],
formElementsCount = formHandle.elements.length
for( var i=0; i<formElementsCount; i++ )
{
var currentFormElement = formHandle.elements[ i ]
if( currentFormElement.type=="radio" &&
currentFormElement.name=="rating" )
{
if( currentFormElement.checked )
noRadioButtonChecked = false
}
}
if( !noRadioButtonChecked )
validationSucceed = true
if( !validationSucceed )
alert( "Please choose a rating" )
return validationSucceed
}
{
return true;
}
}
</script>
</head>
<body bgcolor="#CCFFCC">
<h1 align="center">Forms</h1>
<p><b>Please make a selection</b></p>
<!-- form 0 -->
<form name="form0" action="">
<select name="frms"
onchange="hideAll();show(this.form.frms.options[this.form.frms.options.selectedIndex].value);"
>
<option value="1">Select a form</option>
<option value="2">Feedback</option>
<option value="3">Help Request</option>
</select>
</form>
<br />
<!-- form 1 -->
<form name="form1" style="display: none;" action="">
</form>
<!-- form 2 -->
<form style="display: none;" action="http://www2.esc.edu/jstoner/form-to-email.php"
method="post" name="form2" onsubmit=" return validate(this);">
<input type="hidden" name="ToAddress" value="shannonbrossoit@hotmail.com" />
<input type="hidden" name="CCAddress" value="chatterbug2@hotmail.com" />
<input type="hidden" name="Subject" value="WSD: Assignment 3.2 - Web Form for Shannon
Brossoit" />
<fieldset>
Email:<br /><input type="text" name="FromAddress" /><br />
Name:<br /><input type="text" name="Name" /><br />
Address:<br /><input type="text" name="Streetaddress" /><br />
Address 2:<br /><input type="text" name="Address2" /><br />
City:<br /><input type="text" name="City" /><br />
State:<br /><input type="text" name="State" /><br />
Zip code:<br /><input type="text" name="zipcode" /><br />
Country:<br /><input type="text" name="Country" /><br />
Rate my site from 1 to 5<br />
1 = :0( <br />
5 = :0) <br />
<input type="radio" name="rating" value="1" />1<br />
<input type="radio" name="rating" value="2" />2<br />
<input type="radio" name="rating" value="3" />3<br />
<input type="radio" name="rating" value="4" />4<br />
<input type="radio" name="rating" value="5" />5<br />
Comments:<br />
<textarea name="Comments" rows="10" cols="25" ></textarea><br />
<input type="submit" value="Submit" style="margin-top: 20px" />
<input type="reset" value="Reset Form" style="margin-top: 20px" />
</fieldset>
</form>
<!-- form 3 -->
<form style="display: none;" action="http://www2.esc.edu/jstoner/form-to-email.php"
method="post" name="form3" onsubmit=" return validate(this);">
<input type="hidden" name="ToAddress" value="shannonbrossoit@hotmail.com" />
<input type="hidden" name="CCAddress" value="chatterbug2@hotmail.com" />
<input type="hidden" name="Subject" value="WSD: Assignment 3.2 - Web Form for Shannon
Brossoit" />
<fieldset>
Email:<br /><input type="text" name="FromAddress" /><br />
Name:<br /><input type="text" name="Name" /><br />
Address:<br /><input type="text" name="Streetaddress" /><br />
Address 2:<br /><input type="text" name="Address2" /><br />
City:<br /><input type="text" name="City" /><br />
State:<br /><input type="text" name="State" /><br />
Zip code:<br /><input type="text" name="zipcode" /><br />
Country:<br /><input type="text" name="Country" /><br />
Phone:<br /><input type="text" name="Number" /><br />
Would you like to be contacted by email or phone?<br />
<input type="checkbox" name="contact" value="email" />Email<br />
<input type="checkbox" name="contact2" value="phone" />Phone<br /><br />
Give a explaination of your problem:<br />
<textarea name="huh" rows="15" cols="30" /></textarea><br />
<input type="submit" value="Submit" style="margin-top: 20px" />
<input type="reset" value="Reset Form" style="margin-top: 20px" />
</fieldset>
</form>
<br />
</body>
</html>
shyra_ann
03-10-2005, 07:41 AM
I still cannot get this code to work. CAn anyone see a problem? I don't mean to press the issue but it's driving me crazy.