tags:

views:

65

answers:

3

Bellow is my php code .

    <div class="poller">

                <div class="poller_question" id="poller_question2">
                <p class="pollerTitle">Would you join a Community Action Committee?</p>
<p class="pollerOption"><input type="radio" value="6" name="vote[2]" id="pollerOption6">
<label for="pollerOption6" id="optionLabel6">Yes</label></p><p class="pollerOption">
<input type="radio" value="7" name="vote[2]" id="pollerOption7"><label for="pollerOption7" 
id="optionLabel7">Maybe</label></p><p class="pollerOption"><input type="radio" value="8" 
name="vote[2]" id="pollerOption8"><label for="pollerOption8" id="optionLabel8">No</label></p>           
                <a href="#" onclick="castMyVote(2,document.forms[0])"><imgsrc="images/vote_button.gif" border="0"></a>

                </div>
                <div class="poller_waitMessage" id="poller_waitMessage2">
                    Getting poll results. Please wait...
                </div>
                <div class="poller_results" id="poller_results2">
                <!-- This div will be filled from Ajax, so leave it empty --></div>
            </div>

Bellow is my javascript code

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();
        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 

    }   
}   

form php i call a javascript method named "castMyVote" .The javascript is

var elements = formObj.elements['vote[' + pollId + ']'];

create problem ? why ?How to solve it?var elements have no value

A: 

What is the error you get?

Peter Loron
it should be a comment and not answer
Xinus
Yes. I'd already left it as an answer, and didn't see any way to move it to a comment.
Peter Loron
A: 

Try

var elements = document.getElementsByName("vote["+pollId+"]");
S.Mark
A: 

If your problem is that your elements variable is not getting the correct value, it is because the second parameter on your function CastMyVote requires a form but you do not have a form in your html. try this:

 <div class="poller">
<form method="post" action="#">
                <div class="poller_question" id="poller_question2">
                <p class="pollerTitle">Would you join a Community Action Committee?</p>
<p class="pollerOption"><input type="radio" value="6" name="vote[2]" id="pollerOption6">
<label for="pollerOption6" id="optionLabel6">Yes</label></p><p class="pollerOption">
<input type="radio" value="7" name="vote[2]" id="pollerOption7"><label for="pollerOption7" 
id="optionLabel7">Maybe</label></p><p class="pollerOption"><input type="radio" value="8" 
name="vote[2]" id="pollerOption8"><label for="pollerOption8" id="optionLabel8">No</label></p>           
                <a href="#" onclick="castMyVote(2,document.forms[0])"><imgsrc="images/vote_button.gif" border="0"></a>

                </div>
                <div class="poller_waitMessage" id="poller_waitMessage2">
                    Getting poll results. Please wait...
                </div>
                <div class="poller_results" id="poller_results2">
                <!-- This div will be filled from Ajax, so leave it empty --></div>
</form>
            </div>

I just put your divs and inputs inside the form.

Edit: your <imgsrc="images/vote_button.gif" border="0">. typo error?

junmats