Ok I have used the source from that website then and placed it on here: http://www.chamillionairechat.com

So as you can see now, the poll shows were I want it to and looks good

But when you click on a vote, the page goes dodgy

So does anyone know what I can do to fix it and don't forget I want it looking like this website here

Thanks

    I cannot even vote, no submit is performed.

      That's what I am meaning

      I need to upload some files or something 🙁

      Or create some files with some php in

      Can someone help me fix it please 🙂

      Thanks

        Have you tried to create a standard poll without ajax?

          Hi,

          I tested the poll and get a javascript error. Looking at the javascript code it looks like you need to give the div that contains the poll code the id pollAjax, something like

          <div id="pollAjax"><b>Favourite Mixtape?</b>
          <form action="/" method="post" class="poll1">
          <input type="hidden" name="pollNumber" value="26" />
          <input type="radio" name="vote" value="1" onclick="javascript:requestContent('poll/poll.php?vote=1');" />Mixtape Messiah <br />
          <input type="radio" name="vote" value="2" onclick="javascript:requestContent('poll/poll.php?vote=2');" />Mixtape Messiah 2 <br />
          <input type="radio" name="vote" value="3" onclick="javascript:requestContent('poll/poll.php?vote=3');" />Mixtape Messiah 3 <br />
          </form></div>
          

          Just a guess...

          Thomas

            benracer wrote:

            Have you tried to create a standard poll without ajax?

            Yes, but I couldn't find one that would refresh the page automatically as soon as someone votes 🙁

            tsinka wrote:

            Hi,

            I tested the poll and get a javascript error. Looking at the javascript code it looks like you need to give the div that contains the poll code the id pollAjax, something like

            <div id="pollAjax"><b>Favourite Mixtape?</b>
            <form action="/" method="post" class="poll1">
            <input type="hidden" name="pollNumber" value="26" />
            <input type="radio" name="vote" value="1" onclick="javascript:requestContent('poll/poll.php?vote=1');" />Mixtape Messiah <br />
            <input type="radio" name="vote" value="2" onclick="javascript:requestContent('poll/poll.php?vote=2');" />Mixtape Messiah 2 <br />
            <input type="radio" name="vote" value="3" onclick="javascript:requestContent('poll/poll.php?vote=3');" />Mixtape Messiah 3 <br />
            </form></div>
            

            Just a guess...

            Thomas

            Yes I know, but i don't know what could go in the "pollAjax" 🙁

              What about displaying the current poll results ? The AJAX engine sends a request to poll/poll.php. Let the script save the vote and return a html snipplet that display the current poll results. Just the snipplet you would add to the div to display the current poll results.

              The Ajax code you use replaces the contents of the element with id pollAjax with the content the php script returns/prints.

                Sounds good 🙂

                Do you think you could help me code it, because I don't really know how to 🙁

                Thanks

                  How does the current poll.php look like (attach the file to your post) ?

                    I haven't got one 🙁

                    But I do have a "poll.js"

                    //create a XMLHttpRequest Object.
                    if(window.XMLHttpRequest) {
                    	xmlhttp = new XMLHttpRequest(); // Firefox
                    } else {
                    	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
                    }
                    
                    //call this function with url of document to open as attribute
                    function requestContent(url) {
                    	xmlhttp.open("GET",url,true);
                    	xmlhttp.onreadystatechange = statusListener;
                    	xmlhttp.send(null);
                    }
                    
                    // statusListener function is called automatically whenever readystate value of XMLHttpRequest Object changes
                    // see xmlhttp.onreadystatechange =statusListener; statement above.
                    // When readystate is 1 = a loading state. When readystate is 4, content is loaded
                    function statusListener() {
                    
                    /*
                    if (xmlhttp.readyState == 1) {
                    	document.getElementById('pollAjax').innerHTML = "loading..";
                    }
                    */
                    
                    if (xmlhttp.readyState == 4) {
                    	//xmlhttp.responseText is the content of document requested
                    	document.getElementById('pollAjax').innerHTML = xmlhttp.responseText;
                    }
                    }

                    But I just don't have a clue what to add or were to start with this "poll.php" 🙁

                      Ok,

                      as a first step create a file named poll.php in the base directory (DOCUMENT_ROOT). Then change the javascript requests to use that poll.php script, like

                      javascript:requestContent('poll/poll.php?vote=1');"
                      to
                      javascript:requestContent('/poll.php?vote=1');"

                      Just to test add the following content to that poll.php script:

                      <?PHP
                      echo "you submitted: ".$_GET['vote']."<br>";
                      ?>
                      

                      Additionally, replace

                      <div><b>Favourite Mixtape?</b>
                      with
                      <div id="pollAjax"><b>Favourite Mixtape?</b>

                      You should then see "you submitted <vote>" in the poll div after selecting one of the radio buttons.

                        Ok thanks 🙂 It worked great 😃

                        But do you know a way how I can get it to be like this one here?

                        Thanks again

                          Do you have a database (MySQL) ? Create tables to store the votings.
                          Modify the poll.php script so that it takes the get parameter (es e.g. the id of the record that matches the selected item) and update the info in the database. Then select all neccessary data for the current poll from the tables and echo HTML a html snipplet that displays the data.

                            Thanks, but this is the bits I don't understand

                            Could you help me out with the coding please (I don't get what to put 🙁 )

                            Also, yes I do have MYSQL

                            Edit: Will the MYSQL tables be something like this:

                            CREATE TABLE `results` (
                              `id` bigint(20) NOT NULL AUTO_INCREMENT,
                              `option` varchar(255) NOT NULL,
                              `count` bigint(20) NOT NULL DEFAULT '0',
                              KEY `id` (`id`)
                            )
                            
                            CREATE TABLE `ips` (
                            `ip` VARCHAR( 255 ) NOT NULL ,
                            `time` INT NOT NULL
                            )

                              Do you want to have more than one poll in the future ? In that case you should create a table with poll metadata.

                              What is the ip field for (TCP/IP address or something like that) ?

                                Yes I want to add more than one poll in the future

                                And I don't understand the IP thing 🙁

                                  Write a Reply...