<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ajax Poller: sondaggio ajax]]></title><description><![CDATA[<p dir="auto">Ciao a tutti,<br />
ho scaricato lo script originale da qui: www dhtmlgoodies com/index.html?whichScript=ajax-poller<br />
ed avevo intenzione di modificarlo per ottenere una pagina che restituisse i risultati di più sondaggi insieme.</p>
<p dir="auto">Soltanto che quando provo a far visualizzare i risultati di 2 sondaggi insieme il primo non riesce ad impostare bene il grafico con le percentuali, mentre il secondo funziona benissimo.</p>
<p dir="auto">Questi sono i file che ho modificato:</p>
<p dir="auto"><strong>ajax-poller.js</strong> (qui ho solo duplicato questa funzione):</p>
<pre><code>function showVoteResults(pollId,ajaxIndex)
{
    
    document.getElementById('poller_waitMessage' + pollId).style.display='none';
    
    var xml = ajaxObjects[ajaxIndex].response;
    xml = xml.replace(/\n/gi,'');
    
    var reg = new RegExp("^.*?&lt;pollerTitle5&gt;(.*?)&lt;.*$","gi");
    var pollerTitle = xml.replace(reg,'$1');
    
    var resultDiv = document.getElementById('poller_results' + pollId);
    
    var titleP = document.createElement('P');
    titleP.className='result_pollerTitle';
    titleP.innerHTML = pollerTitle;
    resultDiv.appendChild(titleP);    
    
    var options = xml.split(/&lt;option&gt;/gi);
    
    pollVotes[pollId] = new Array();
    totalVotes[pollId] = 0;
    for(var no=1;no&lt;options.length;no++){
        
        var elements = options[no].split(/&lt;/gi);
        var currentOptionId = false;
        for(var no2=0;no2&lt;elements.length;no2++){
            if(elements[no2].substring(0,1)!='/'){
                var key = elements[no2].replace(/^(.*?)&gt;.*$/gi,'$1');
                var value = elements[no2].replace(/^.*?&gt;(.*)$/gi,'$1');
            
                if(key.indexOf('optionText5')&gt;=0){
                    var pOption = document.createElement('P');
                    pOption.className='result_pollerOption';
                    pOption.innerHTML = value;
                    resultDiv.appendChild(pOption);                    
                    
                }
                
                if(key.indexOf('optionId5')&gt;=0){
                    currentOptionId = value/1;
                }
                
                if(key.indexOf('votes5')&gt;=0){
                    var voteDiv = document.createElement('DIV');
                    voteDiv.className='result_pollGraph';
                    resultDiv.appendChild(voteDiv);    
                    
                    var leftImage = document.createElement('IMG');
                    leftImage.src = voteLeftImage;
                    voteDiv.appendChild(leftImage);
                    
                    
                    var numberDiv = document.createElement('DIV');
                    numberDiv.style.backgroundImage = 'url(\'' + voteCenterImage + '\')';
                    numberDiv.innerHTML = '0%';
                    numberDiv.id = 'result_voteTxt' + currentOptionId;
                    voteDiv.appendChild(numberDiv);    
                    
                    var rightImage = document.createElement('IMG');
                    rightImage.src = voteRightImage;
                    voteDiv.appendChild(rightImage);                        
                    
                    pollVotes[pollId][currentOptionId] = value;                    
                    totalVotes[pollId] = totalVotes[pollId]/1 + value/1;
                }
            }
        }
    }
    
    var totalVoteP = document.createElement('P');
    totalVoteP.className = 'result_totalVotes';
    totalVoteP.innerHTML = txt_totalVotes + totalVotes[pollId];
    voteDiv.appendChild(totalVoteP);    
    
    setPercentageVotes(pollId);
    slideVotes(pollId,0);
    
    
    
    
    
    document.getElementById('poller_waitMessage' + pollId).style.display='none';
    
    var xml = ajaxObjects[ajaxIndex].response;
    xml = xml.replace(/\n/gi,'');
    
    var reg = new RegExp("^.*?&lt;pollerTitle6&gt;(.*?)&lt;.*$","gi");
    var pollerTitle = xml.replace(reg,'$1');
    
    var resultDiv = document.getElementById('poller_results' + pollId);
    
    var titleP = document.createElement('P');
    titleP.className='result_pollerTitle';
    titleP.innerHTML = pollerTitle;
    resultDiv.appendChild(titleP);    
    
    var options = xml.split(/&lt;option&gt;/gi);
    
    pollVotes[pollId] = new Array();
    totalVotes[pollId] = 0;
    for(var no=1;no&lt;options.length;no++){
        
        var elements = options[no].split(/&lt;/gi);
        var currentOptionId = false;
        for(var no2=0;no2&lt;elements.length;no2++){
            if(elements[no2].substring(0,1)!='/'){
                var key = elements[no2].replace(/^(.*?)&gt;.*$/gi,'$1');
                var value = elements[no2].replace(/^.*?&gt;(.*)$/gi,'$1');
            
                if(key.indexOf('optionText6')&gt;=0){
                    var pOption = document.createElement('P');
                    pOption.className='result_pollerOption';
                    pOption.innerHTML = value;
                    resultDiv.appendChild(pOption);                    
                    
                }
                
                if(key.indexOf('optionId6')&gt;=0){
                    currentOptionId = value/1;
                }
                
                if(key.indexOf('votes6')&gt;=0){
                    var voteDiv = document.createElement('DIV');
                    voteDiv.className='result_pollGraph';
                    resultDiv.appendChild(voteDiv);    
                    
                    var leftImage = document.createElement('IMG');
                    leftImage.src = voteLeftImage;
                    voteDiv.appendChild(leftImage);
                    
                    
                    var numberDiv = document.createElement('DIV');
                    numberDiv.style.backgroundImage = 'url(\'' + voteCenterImage + '\')';
                    numberDiv.innerHTML = '0%';
                    numberDiv.id = 'result_voteTxt' + currentOptionId;
                    voteDiv.appendChild(numberDiv);    
                    
                    var rightImage = document.createElement('IMG');
                    rightImage.src = voteRightImage;
                    voteDiv.appendChild(rightImage);                        
                    
                    pollVotes[pollId][currentOptionId] = value;                    
                    totalVotes[pollId] = totalVotes[pollId]/1 + value/1;
                }
            }
        }
    }
</code></pre>
<p dir="auto"><strong>ajax-poller-cast-vote-php.php</strong> (qui ho fatto un'altra query al db per estrapolare i dati anche del secondo sondaggio):</p>
<pre><code>$res5 = mysql_query("select ID,pollerTitle from poller where ID='5'");
    if($inf5 = mysql_fetch_array($res5)){
        echo "&lt;pollerTitle5&gt;".$inf5["pollerTitle"]."&lt;/pollerTitle5&gt;\n";
        
        $resOptions5 = mysql_query("select ID,optionText from poller_option where pollerID='".$inf5["ID"]."' order by pollerOrder") or die(mysql_error());
        while($infOptions5 = mysql_fetch_array($resOptions5)){
            echo "&lt;option&gt;\n";
            echo "\t&lt;optionText5&gt;".$infOptions5["optionText"]."&lt;/optionText5&gt;\n";                    
            echo "\t&lt;optionId5&gt;".$infOptions5["ID"]."&lt;/optionId5&gt;\n";                    
            
            $resVotes5 = mysql_query("select count(ID) from poller_vote where optionID='".$infOptions5["ID"]."'");
            if($infVotes5 = mysql_fetch_array($resVotes5)){
                echo "&lt;votes5&gt;".$infVotes5["count(ID)"]."&lt;/votes5&gt;\n";                            
            }                                        
            echo "&lt;/option&gt;";                
            
        }                
    }
    
    $res6 = mysql_query("select ID,pollerTitle from poller where ID='6'");
    if($inf6 = mysql_fetch_array($res6)){
        echo "&lt;pollerTitle6&gt;".$inf6["pollerTitle"]."&lt;/pollerTitle6&gt;\n";
        
        $resOptions6 = mysql_query("select ID,optionText from poller_option where pollerID='".$inf6["ID"]."' order by pollerOrder") or die(mysql_error());
        while($infOptions6 = mysql_fetch_array($resOptions6)){
            echo "&lt;option&gt;\n";
            echo "\t&lt;optionText6&gt;".$infOptions6["optionText"]."&lt;/optionText6&gt;\n";                    
            echo "\t&lt;optionId6&gt;".$infOptions6["ID"]."&lt;/optionId6&gt;\n";                    
            
            $resVotes6 = mysql_query("select count(ID) from poller_vote where optionID='".$infOptions6["ID"]."'");
            if($infVotes6 = mysql_fetch_array($resVotes6)){
                echo "&lt;votes6&gt;".$infVotes6["count(ID)"]."&lt;/votes6&gt;\n";                            
            }                                        
            echo "&lt;/option&gt;";                
            
        }                
    }
</code></pre>
<p dir="auto">Confido in un vostro aiutino... :?:bho:<br />
Ciao e grazie</p>
]]></description><link>https://dev.connect.gt/topic/156698/ajax-poller-sondaggio-ajax</link><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 01:54:49 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/156698.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 21 Aug 2011 06:28:29 GMT</pubDate><ttl>60</ttl></channel></rss>