我无法执行“castMyVote”功能。我在poll.php投票但在index.php投票时没用。我确保所有的php和js都在正确的路径中。我在Index.php中尝试了另一个函数“displayvotewithoutvote”,我可以在没有投票的情况下显示统计数据。
的index.php:
include('poll.php');
poll.php:
<a href="#mainContainer" onclick="castMyVote(<?php echo $pollerId;?>,document.forms[0])"><img src="images/vote_button.gif"></a>
ajax.js:
function castMyVote(pollId,formObj)
{
var elements = formObj.elements['vote[' + pollId + ']'];
var optionId = false;
**for(var no=0;no<elements.length;no++){
if(elements[no].checked)optionId = elements[no].value;
}**
Poller_Set_Cookie('dhtmlgoodies_poller_' + pollId,'1',6000000);
if(optionId){
var ajaxIndex = ajaxObjects.length;
ajaxObjects[ajaxIndex] = new sack(); //an api from simple ajax code kit
ajaxObjects[ajaxIndex].requestFile = serverSideFile + '?pollId=' + pollId + '&optionId=' + optionId;
prepareForPollResults(pollId);
ajaxObjects[ajaxIndex].onCompletion = function(){ showVoteResults(pollId,ajaxIndex); }; // Specify function that will be executed after file has been found
ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
}
}
更新:在上面显示的ajax.js中,在我包含警报之后它没有响应,我在这里有点不对劲:
for(var no=0;no<elements.length;no++){
if(elements[no].checked)optionId = elements[no].value;
}
答案 0 :(得分:1)
请在poll.php中尝试此代码
<a href="#mainContainer"><img src="images/vote_button.gif" onclick="castMyVote(<?php echo $pollerId;?>,document.forms[0])"></a>
这可能会对你有帮助。
谢谢,
汉字
答案 1 :(得分:0)
你在js中得到了pollid吗?
var pollid =“”;
的onclick =“castMyVotepollid,....
试试这个