<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>
在我的劇本,我有:JS似乎沒有能夠找到自己的狀態
變種R = document.forms.pollvoteform1.poll_option1;
但我得到的錯誤:
document.forms.pollvoteform1未定義 我不明白爲什麼。由於pollvoteform1和poll_option_1都在那裏。
//更新:完整的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");
}
}
沒有看到您的發佈代碼的問題,因此它可能在別處,但我強烈建議儘可能使用id屬性和getElementById。 – annakata 2009-05-27 12:18:03
你在哪裏對。我忘了在同一頁上關閉一個不同的表格:-( – sanders 2009-05-27 12:52:04
你可以更新你的標題來說javascript而不是js,並且添加瀏覽器和版本,這樣就更清楚了。 – 2009-05-27 12:55:07