...

View Full Version : Form validates regardless of boolean value! :)



3D_Dog_Man
08-17-2005, 09:14 AM
Hi Everyone,

I am attempting to validate a form before forwarding it to the server. However my server side code is being called regardless of the boolean value that my javascript returns.

My form markup looks like so

<form action="CraftSurvey" id="surveyform" method="post" name="surveyform" onsubmit="checkVote();">
<p align="left">
<input type="radio" name="surveybutton" value="Bears">

<span class="black_verdana_text">Bears
</span></p>
<p align="left">
<input type="radio" name="surveybutton" value="Country & Garden">
<span class="black_verdana_text">Country & Garden</span>
</p>
<p align="left">
<input type="radio" name="surveybutton" value="Floral">
<span class="black_verdana_text">Floral
</span></p>

<p align="left">
<input type="radio" name="surveybutton" value="Hearts">
<span class="black_verdana_text">Hearts</span>
</p>
<p align="left">
<input type="radio" name="surveybutton" value="Wording">
<span class="black_verdana_text">Wording</span>
</p>
<p align="center">
<input name="surveyvote" type="submit" class="black_verdana_text" value="Vote Now">

</p>
</form>

And my form validation script looks like so:

<script type="text/JavaScript">
//<!--
function checkVote()
{
var valid = false;

var bears = document.surveyform.surveybutton[0];
var country = document.surveyform.surveybutton[1];
var floral = document.surveyform.surveybutton[2];
var hearts = document.surveyform.surveybutton[3];
var wording = document.surveyform.surveybutton[4];

if((bears.checked == false) && (country.checked == false) && (floral.checked == false) && (hearts.checked == false) && (wording.checked == false))
{
alert("Please select a category before voting.");
}
else
{
valid = true;
}

return valid;
}
//-->
</script>

The script is inside the head section of the html document.

If anybody has any suggestions regarding the cause of this challenge they will be greatly appreciated.

Thanks

Davo

Kor
08-17-2005, 10:50 AM
You forgot to use the return conditional

<form action="CraftSurvey" id="surveyform" method="post" name="surveyform" onsubmit="return checkVote();">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum