More FORM help

They have: 117 posts

Joined: Feb 2000

Hi,

OK, this is driving me crazy. I have something like the following:

<FORM NAME="voteForm" onSubmit="return valForm();" METHOD="POST">

Your name: <br>
<INPUT TYPE="text" NAME="Name" SIZE="35"><br>

Your email address: <br>
<INPUT TYPE="text" NAME="email" SIZE="35"><br>
<p>
President:<br>
<INPUT TYPE="radio" NAME="Pres" VALUE="John">John
<INPUT TYPE="radio" NAME="Pres" VALUE="Lauren">Lauren
<p>
Vice-President:<br>
<INPUT TYPE="radio" NAME="VPres" VALUE="Kevin">Kevin
<INPUT TYPE="radio" NAME="VPres" VALUE="Jay">Jay

I want to do some checking of the form in the function valForm. I can check whether or not the user entered their name for example by doing:
if(document.voteForm.Name.value==""){
alert("You didn't enter your name");

HOWEVER, I can not seem to be able to reference what was checked as an entry for either radio button. I tried:
if(document.voteForm.Pres.value=="Lauren")
for example, but this does not work. What am I doing wrong? Thanks a lot!

Bob

They have: 89 posts

Joined: Sep 1999

Bob-

This should do the trick.

<script language="JavaScript"><!--
function validate(){
if (voteForm.Pres[0].checked == false && voteForm.Pres[1].checked == false){
alert("You must choose one fool!");
return false;
}
}
//--></script>

<FORM NAME="voteForm" onSubmit="return validate();" METHOD="POST">
President:<br>
<INPUT TYPE="radio" NAME="Pres" VALUE="John">John
<INPUT TYPE="radio" NAME="Pres" VALUE="Lauren">Lauren
<input type=submit value=go>
</form>

They have: 117 posts

Joined: Feb 2000

RC,

Thanks! That worked great! (actually I had to add document. in front of voteForm.Pres[x].checked to get it to work).

OK, let me try to take it a step further. Now I can easily dtermine within my script which candidates were voted for. Is there an easy way to be able to use the script to tally these votes as they come in from different users? Maybe there's a way to have a text file on my server with total vote numbers for each candidate which could be read, incremented according to which candidate was selected, and then written back out by my script? Or perhaps there's another way? Thanks again.

Bob

They have: 231 posts

Joined: Feb 2000

Bob: you can tally your results into a text file but you cant do it with client-side JavaScript. You need to use CGI for this using Perl, ASP or PHP etc... Try posting for help in either the Cgi & Perl Forum or the Misc. Scripting Languages Forum.

:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.