<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>
在我的剧本中我有:
var r = document.forms.pollvoteform1.poll_option1;
但我收到错误:
document.forms.pollvoteform1未定义 我不明白为什么。由于pollvoteform1和poll_option_1都在那里。
// update:完整的js代码
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");
}
}
答案 0 :(得分:1)
要么是
var r=document.forms['pollvoteform1'].poll_option1;
或者如果不起作用
var r=document.forms[0].poll_option1;
答案 1 :(得分:1)
尝试在表单中添加ID标记。它应该与名称标签相同。
答案 2 :(得分:0)
您的代码在IE7和Firefox 3.0.10中运行良好。
您使用的是哪种浏览器?