views:

104

answers:

3
<div class="poll"> 

 <h1>Poll</h1>
 <form name="pollvoteform1" method="post" xxaction="/plugins/content_types/poll/poll.php">
 <p class="tekstaanmelden"><b>Het regent </b></p>
    <input type="hidden" name="poll" value="1">
    <input type="hidden" name="cmd" value="">
            <div class="pollOption"><input type="radio"  class="stelling" name="poll_option1" value="1"></div><div class="pollOptionText">Eens</div><br clear="all"><div class="pollOption"><input type="radio"  class="stelling" name="poll_option1" value="2"></div><div class="pollOptionText">Oneens</div><br clear="all"><div class="pollOption"><input type="radio"  class="stelling" name="poll_option1" value="3"></div><div class="pollOptionText">Waar</div><br clear="all"><div class="pollOption"><input type="radio"  class="stelling" name="poll_option1" value="4"></div><div class="pollOptionText">Niet waar</div><br clear="all">
   <input type="button" name="bt_submit" class="pollButtonNormal" onmouseover="this.className='pollButtonHigh';" onmouseout="this.className='pollButtonNormal';" value="Stem" onclick="javascript:vote1();" style="padding-bottom: 3px; margin-top: 5px;">
   <input type="button" name="bt_submit2" class="pollButtonNormal" onMouseOver="this.className='pollButtonHigh';" onMouseOut="this.className='pollButtonNormal';" value="Bekijk resultaten" onclick="javascript:viewResults1();"  style="padding-bottom: 3px; margin-top: 5px; width:98px;">
    </form>
</div>
<div style="display:none;width: 175px;">

    <form><input type="button" name="bt_submit" class="pollButtonNormal" onmouseover="this.className='pollButtonHigh';" onmouseout="this.className='pollButtonNormal';" value="Resultaten" onclick="javascript:viewResults1();" style="padding-bottom: 3px; margin-top: 10px; "></form>
</div>

In my script I have:

var r=document.forms.pollvoteform1.poll_option1;

But I get the error:

document.forms.pollvoteform1 is undefined And I don't understand why. Since the pollvoteform1 and the poll_option_1 are both there.

//update: the full js code

    function vote() {
var r=document.forms.pollvoteform1.poll_option1;
var voted=false;
if (r.value!=null && r.checked){
voted=true;
} else {
for (i=0;i<r.length;i++){
if (r[i].checked) {
voted=true;
break;
}
}}

if (voted) {
document.forms.pollvoteform1.submit();
} else {
alert("you didn't make a choice yet");
}
}
+1  A: 

Its either

var r=document.forms['pollvoteform1'].poll_option1;

or if that dosnt work

var r=document.forms[0].poll_option1;
nullptr
the first option gave the same error.By the second one I get:r is undefined
sanders
Im not sure what you are trying to do but maybe you want var r=document.forms[0].poll_option1.value;That would make r = 2
nullptr
i updated my startpost.
sanders
+1  A: 

Try adding an ID tag to the form. It should be the same as the name tag.

Antonio Louro
same error as before
sanders
also add ids to the input (e.g. poll_option1)
Kevin Hakanson
A: 

Your code is working fine in IE7 and Firefox 3.0.10.

Which browser you are using?

Green Techy
I am using firefox (latest version)
sanders