views:

29

answers:

2

I couldn't get "castMyVote" function to execute. It worked when I cast a vote in poll.php but not in index.php. I have ensure all php and js are in correct path. I tried another function "displayvotewithoutvote" in Index.php, I could display statistic without vote.

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    

    }   
}

Update: in ajax.js as showing above, it doesn't response after I include alert after, I afraid something wrong here:

for(var no=0;no<elements.length;no++){
if(elements[no].checked)optionId = elements[no].value;
}
A: 

Hello,

Please try this code in your poll.php

<a href="#mainContainer"><img src="images/vote_button.gif" onclick="castMyVote(<?php echo $pollerId;?>,document.forms[0])"></a>

This may help you.

Thanks,

Kanji

Kanji
Not working. however, I found I could not display the alert at this point:
proyb3
refer to my update post.
proyb3
A: 

are you getting the pollid in the js?

var pollid="";

onclick="castMyVotepollid,....

try this

zod