Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:31:15+00:00 2026-06-11T05:31:15+00:00

I downloaded the PHP voting script from this website: I have installed this and

  • 0

I downloaded the PHP voting script from this website:

I have installed this and it works perfectly on my website, however I am looking at customising it slightly so that once a user has voted it then redirects them to a new page, or ideally opens up a lightbox.

I have narrowed it down to a javascript problem, and the javascript file is within the voting.js file.

Below is the following code found in that file:

// Ajax Voting Script - http://www.coursesweb.net
var ivotings = Array();         // store the items with voting
var ar_elm = Array();       // store the items that will be send to votAjax()
var i_elm = 0;                  // Index for elements aded in ar_elm
var itemvotin = '';       // store the voting of voted item
var votingfiles = 'votingfiles/';      // directory with files for script
var advote = 0;      // variable checked in addVote(), if is 0 cann vote, else, not

// gets all DIVs, store in $ivotings, and in $ar_elm DIVs with class: "vot_plus", "vot_updown", and ID="vt_..", sends to votAjax()
var getVotsElm = function () {
  var obj_div = document.getElementsByTagName('div');
  var nrobj_div = obj_div.length;
  for(var i=0; i<nrobj_div; i++) {
    // if contains class and id
    if(obj_div[i].className && obj_div[i].id) {
        var elm_id = obj_div[i].id;
      // if class "vot_plus", "vot_updown1", "vot_updown2", or "vot_poll" and id begins with "vt_"
      if((obj_div[i].className=='vot_plus' || obj_div[i].className=='vot_updown1' || obj_div[i].className=='vot_updown2') && elm_id.indexOf("vt_")==0) {
        ivotings[elm_id] = obj_div[i];       // store object item in $ivotings

        ar_elm[i_elm] = elm_id;     // add item_ID in $ar_elm array, to be send in json string tp php
        i_elm++;             // index order in $ar_elm
      }
    }
  }
  // if there are elements in "ar_elm", send them to votAjax()
  if(ar_elm.length>0) votAjax(ar_elm, '');      // if items in $ar_elm pass them to votAjax()
};

// add the ratting data to element in page
function addVotData(elm_id, vote, nvotes, renot) {
  // exists elm_id stored in ivotings
  if(ivotings[elm_id]) {
    // sets to add "onclick" for vote up (plus), if renot is 0
    var clik_up = (renot == 0) ? ' onclick="addVote(this, 1)"' : ' onclick="alert(\'You already voted\')"';

    // if vot_plus, add code with <img> 'votplus', else, if vot_updown1/2, add code with <img> 'votup',  'votdown'
    if(ivotings[elm_id].className == 'vot_plus') {    // simple vote
      ivotings[elm_id].innerHTML = '<h4>'+ vote+ '</h4><span><img src="'+votingfiles+'votplus.gif" alt="1" title="Vote"'+ clik_up+ '/></span>';
    }
    else if(ivotings[elm_id].className=='vot_updown1') {   // up/down with total Votes
      // sets to add "onclick" for vote down (minus), if renot is 0
      var clik_down = (renot == 0) ? ' onclick="addVote(this, -1)"' : ' onclick="alert(\'You already voted\')"';

      ivotings[elm_id].innerHTML = '<div id="nvotes">Votes: <b>'+ nvotes+ '</b></div><h4>'+ vote+ '</h4><span><img src="'+votingfiles+'votup.png" alt="Vote Up" title="Vote Up"'+ clik_up+ '/> <img src="'+votingfiles+'votdown.png" alt="Vote Down" title="Vote Down"'+ clik_down+ '/></span>';
    }
    else if(ivotings[elm_id].className=='vot_updown2') {      // up/down with number of votes up and down
      var nvup = (nvotes*1 + vote*1) /2;       // number of votes up
      var nvdown = nvotes - nvup;              // number of votes down

      // sets to add "onclick" for vote down (minus), if renot is 0
      var clik_down = (renot == 0) ? ' onclick="addVote(this, -1)"' : ' onclick="alert(\'You already voted\')"';

      ivotings[elm_id].innerHTML = '<h4>'+ vote+ '</h4><span><img src="'+votingfiles+'votup.png" alt="Vote Up" title="Vote Up"'+ clik_up+ '/> <img src="'+votingfiles+'votdown.png" alt="Vote Down" title="Vote Down"'+ clik_down+ '/></span><div id="nupdown"><b id="nvup">'+ nvup+ '</b> &nbsp; &nbsp; <b id="nvdown">'+ nvdown+ '</b></div>';
    }
  }
}

// Sends data to votAjax(), that will be send to PHP to register the vote
function addVote(ivot, vote) {
  // if $advote is 0, can vote, else, alert message
  if(advote == 0) {
    var elm = Array();
    elm[0] = ivot.parentNode.parentNode.id;      // gets the item-name that will be voted

    ivot.parentNode.innerHTML = '<i><b>Thanks</b></i>';
    votAjax(elm, vote);
  }
  else alert('You already voted');
}

/*** Ajax ***/

// create the XMLHttpRequest object, according to browser
function get_XmlHttp() {
  var xmlHttp = null;           // will stere and return the XMLHttpRequest

  if(window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();     // Forefox, Opera, Safari, ...
  else if(window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");     // IE

  return xmlHttp;
}

// sends data to PHP and receives the response
function votAjax(elm, vote) {
  var cerere_http =  get_XmlHttp();     // get XMLHttpRequest object

  // define data to be send via POST to PHP (Array with name=value pairs)
  var datasend = Array();
  for(var i=0; i<elm.length; i++) datasend[i] = 'elm[]='+elm[i];
  // joins the array items into a string, separated by '&'
  datasend = datasend.join('&')+'&vote='+vote;

  cerere_http.open("POST", votingfiles+'voting.php', true);         // crate the request

  cerere_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    // header for POST
  cerere_http.send(datasend);       //  make the ajax request, poassing the data

  // checks and receives the response
  cerere_http.onreadystatechange = function() {
    if (cerere_http.readyState == 4) {
      // receives a JSON with one or more item:[vote, nvotes, renot]
      eval("var jsonitems = "+ cerere_http.responseText);

      // if jsonitems is defined variable
      if (jsonitems) {
        // parse the jsonitems object
        for(var votitem in jsonitems) {
          var renot = jsonitems[votitem][2];        // determine if the user can vote or not

          // if renot=3 displays alert that already voted, else, continue with the voting reactualization
           if(renot == 3) {
            alert("You already voted \n You can vote again tomorrow");
            window.location.reload(true);       // Reload the page
          }
          else addVotData(votitem, jsonitems[votitem][0], jsonitems[votitem][1], renot);    // calls function that shows voting
        }
      }

      // if renot is undefined or 2 (set to 1 NRVOT in voting.php), after vote, set $advote to 1
      if(vote != '' && (renot == undefined || renot == 2)) advote = 1;
      }
  }
}

// this function is used to access the function we need after loading page
function addLoadVote(func) {
  var oldonload = window.onload; 

  // if the parameter is a function, calls it with "onload"
  // otherwise, adds the parameter into a function, and then call it
  if (typeof window.onload != 'function') window.onload = func;
  else { 
    window.onload = function() { 
      if (oldonload) { oldonload(); } 
      func();
    } 
  } 
}

addLoadVote(getVotsElm);            // calls getVotsElm() after page loads

I did have a go at doing this myself and it did work in certain browsers, but not others. All I did was add change the code on line 66 from:

ivot.parentNode.innerHTML = ‘Thanks‘;

to:

ivot.parentNode = window.location = “register2.php”;

But as I said, this only works on certain browsers as on other browsers it doesn’t add the information to the database, anyone know how I can resolve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:31:16+00:00Added an answer on June 11, 2026 at 5:31 am

    The ajax request and the database operations are executed in the votAjax(elm, vote). So you have to add the code for redirecting after the execution of that request.

    Most likely between lines 100-115

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I downloaded and manually installed NERDTree from http://www.vim.org/scripts/script.php?script_id=1658 @hits ➜ .vim rvm:(-ruby-1.9.2) ls -laR
I am trying to make a Postgres PHP backup script. I have downloaded one
I have recently downloaded the FFmpeg-PHP extension (extracted from ffmpeg-php53-win32-vc9-all.zip) for PHP and I
When I look through the source code files I have downloaded from the PHP
I downloaded color sample pack from http://vim.sourceforge.net/scripts/script.php?script_id=625 it says i should unzip and place
I have downloaded a free astrology script in PHP. The script receives some data
I have downloaded php 5.4.0 from php.net and i want to upgrade it on
i've this problem for days... I have to load from php the entire html
I have just downloaded a PHP blog script and am having a few issues
I have downloaded and added this very simple, one file, php web file explorer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.