morthian — 2013-09-13T04:20:43-04:00 — #1
<a id="voteup" href="#" onclick="vote(0,1);">Vote Up</a>
Inside the function that's supposed to change the value, I've been trying to use something like:
document.getElementById("voteup").onclick = "vote("+itemID+",1);";
Needless to say, it's not working.
It works fine to change the href value though...
e.g.: document.getElementById("voteup").href = "vote.php?id="+itemID+"&vote=1";
pullo — 2013-09-13T08:03:59-04:00 — #2
Could you give us a brief example of what you are trying to do (obviously something to do with upvotes) and provide a minimum amount of code that we can run to recreate your issue?
felgall — 2013-09-13T17:46:19-04:00 — #3
You shouldn't be using code like that at all.
morthian — 2013-09-14T03:41:03-04:00 — #4
I was trying to keep it simple, but I can provide more code...
<div id="title" style="text-align:center; font-weight:bold;">---</div>
<div id="vote" style="text-align:center;">
<a id="voteup" href="#" onclick="submitVote(0,1);">[Vote Up]</a> | <a id="votedown" href="#" onclick="submitVote(0,0);">[Vote Down]</a>
document.getElementById("voteup").onclick = 'submitVote('+jwplayer().getPlaylistItem().mediaid+',1);';
document.getElementById("votedown").onclick = 'submitVote('+jwplayer().getPlaylistItem().mediaid+',0);';
document.getElementById("title").innerHTML = jwplayer().getPlaylistItem().title;
I'm trying to use AJAX so that the page doesn't reload when somebody votes on the video currently playing from the playlist.
I didn't include the AJAX code, but basically the function submitVote() sends a request to a PHP vote script.
The function uses two integer variables, the first one is the ID of the video, which should be updated in the vote links upon each video to match the ID of the current video. The second is just the vote (0 for vote down; 1 for vote up).
Before I started on the AJAX, the links pointed directly to the vote script, and there was no problem getting the variables in the href to change upon each video.
The title still changes just fine.
pullo — 2013-09-14T05:58:32-04:00 — #5
So to summarize your problem:
You some videos that people can vote on, these are identified by their id.
You have two links per video, one for "Vote up" and one for "Vote down".
You also have a list of the videos with a tally of up-votes and down-votes.
When someone hits either the "Vote up" or the "Vote down" link on any of the videos, you want to submit an AJAX request to a PHP script which will then update the tally of up-votes and down-votes (presumably in a database).
Once the AJAX request has completed, you want to update the tally of up-votes and down-votes for the respective videos on your page.
Did I get that right?
morthian — 2013-09-14T06:37:03-04:00 — #6
But as felgall basically suggested... maybe I'm going about this all wrong. =/
pullo — 2013-09-14T07:01:39-04:00 — #7
Why do you need to do this?
This isn't how AJAX works.
Well, I can help you with that, but it's important that we understand what you are trying to do first.
Would it help if I made a simple example page doing what I suggested above?
If so, do you mind using the jQuery library to implement the AJAX functionality?