Hi, im trying to create some poll but did receiving some problems.
I used this this poll :
but my problem is, that script by default WILL displaying the result RIGHT after the user have voted and click the vote button.
However, i did not want the user show the result page after they vote, instead they will see like succesfull page after vote.
And i think the problems are on this js (as this script mostly configurated via this js )
// Ajax Voting Poll Script - http://coursesweb.net
// messages displayed
var vplang = {
'-1': '- You must be logged in to can vote',
'0': 'Already Voted',
'1': '- You can vote one poll per day'
}
var vpolls = Array(); // stores the polls for voting
var vphpurl = 'vpoll/vpoll.php'; // store the address added in "action" attribute, in form of poll
// gets all DIVs, store in $vpolls the DIVs with ID="vp_..", the poll-id (idp) in $idpolls, and sends to vpAjax()
var getPolls = function () {
var obj_div = document.getElementsByTagName('div');
var nrobj_div = obj_div.length;
for(var i=0; i<nrobj_div; i++) {
// if contains "id", and "id" starts with "vp_"
if(obj_div[i].id && obj_div[i].id.indexOf("vp_")==0) {
var elm_id = obj_div[i].id;
var idp = elm_id.match(/[0-9]+/); // the poll-id
vpolls[elm_id] = obj_div[i]; // store object item in $vpolls
var vpexists = 1; // to know there is poll item in page, to call vpAjax()
if(document.getElementById('vpf'+idp)) {
vphpurl = document.getElementById('vpf'+idp).action;
disableEnableSbm(document.getElementById('vpf'+idp)); // to register onclick to poll items
}
}
}
// if there are elements in "vpolls", (vpexists) calls vpAjax() to get {voted:polls_voted_by_user}
if(vpexists) vpAjax('voted=idps', '');
};
// disables submit button, then registers onclick to radio buttons of poll to enables the submit button. Receives the form
function disableEnableSbm(frm) {
frm.sbm.setAttribute('disabled', 'disabled');
var vpitems = frm.item;
nr_vpitems = vpitems.length;
for(var i=0; i<nr_vpitems; i++) {
vpitems[i].onclick = function() { frm.sbm.removeAttribute('disabled');}
}
}
// disable poll votting, change the value of its Submit button, disables the radio buttons (idps=array with 'idp')
function disablePoll(voted, idps) {
// function called to disable poll items, all the radio buttons with name="item" (in form with poll items)
var disableItem = function(idp) {
if(document.getElementById('vpf'+idp)) {
var vpitems = document.getElementById('vpf'+idp).item;
var nr_vpitems = vpitems.length;
for(var i=0; i<nr_vpitems; i++) {
vpitems[i].setAttribute('disabled', 'disabled');
}
}
}
// if itemss in $idps, traverses the idps
var nridps = idps.length;
if(nridps > 0) {
for(var i=0; i<nridps; i++) {
// if exists elm_id stored in vpolls, disable the voted polls
if(vpolls['vp_'+idps[i]]) {
if(document.getElementById('vpf'+idps[i])) {
document.getElementById('vpf'+idps[i]).sbm.value = vplang[voted];
document.getElementById('vpf'+idps[i]).sbm.setAttribute('disabled', 'disabled');
disableItem(idps[i]); // to disable radio buttons
}
}
}
}
// if $voted is 1, disables allt the polls stored in $vpolls exxcepts poll with Submit='Already Voted'
if(voted == 1 || voted == -1) {
for(var elm_id in vpolls) {
var idp = elm_id.match(/[0-9]+/); // the poll-id
if(document.getElementById('vpf'+idp)) {
if(document.getElementById('vpf'+idp).sbm.value != vplang[voted]) {
document.getElementById('vpf'+idp).sbm.style.display = 'none'; // hides submit button
disableItem(idp); // to disable radio buttons
document.getElementById('vpf'+idp).innerHTML += '<h4 style="color:#fe0000;">'+ vplang[voted]+ '</h4>';
}
}
}
}
}
// called wen the poll-form is submited. Sends data to vpAjax(), that will be send to PHP to register the vote
function votePoll(frm) {
var idp = frm.idp.value; // gets poll-id
// gets the value of checked radio button
var vpitems = frm.item;
nr_vpitems = vpitems.length;
for(var i=0; i<nr_vpitems; i++) {
if(vpitems[i].checked == true) { var vpitem = vpitems[i].value; break;}
}
// calls the vpAjax() with data to be send to php, and "id" of the DIV with the form
vpAjax('idp='+idp+'&item='+encodeURIComponent(vpitem), 'vp_'+idp);
frm.sbm.setAttribute('disabled', 'disabled'); // disables submit
return false;
}
/*** Ajax ***/
// sends data to PHP and receives the response
function vpAjax(datasend, eid) {
var cerere_http = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); // get XMLHttpRequest object
cerere_http.open("POST", vphpurl, true); // crate the request
cerere_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // header for POST
cerere_http.send(datasend +'&ajx=1'); // 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 voted:idp
eval("var objson = "+ cerere_http.responseText);
// if objson is defined variable
if (objson) {
var idps = []; var i = 0;
// parse the objson object
for(var idp in objson) {
if(document.getElementById('vp_'+ idp)) {
idps[i] = idp; i++;
document.getElementById('vp_'+ idp).innerHTML = objson[idp] +'<div id="alreadyv">'+ vplang[0] +'</div>';
}
}
disablePoll(objson.voted, idps); // to disable poll voting
}
}
}
}
// 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(getPolls); // calls getPolls() after page loads
anyone please help me out, urgently needed