Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery many to many relation
    primarykey
    data
    text
    <p>Hi I'm making a picture competition page (with different rules)</p> <p>I can't seem to wrap my head around this 'problem'</p> <p>The rule is: A user can vote for ONE picture, but not his own. and he is able to remove his vote, and vote for another.</p> <p>I have PHP to check for all that, and it works fine.</p> <p>The type is 0 is this case</p> <pre><code>function addVote(pictureID, competitionID, type){ $.post('vote.php', {pictureID:pictureID, competitionID:competitionID, vote:1}, function(data){ if (data == 'success') { $("#comp_voteButton_"+pictureID).text('Remove vote'); $("#comp_voteButton_"+pictureID).addClass("alreadyVoted"); $("#comp_voteButton_"+pictureID).attr("onclick", "remVote(" + pictureID + ", " + competitionID + ")") if (type == 0){ $('.button:not(.disabled, #comp_voteButton_'+pictureID+')').text('Only one vote permitted'); $('.button:not(.disabled, #comp_voteButton_'+pictureID+')').removeClass('alreadyVoted'); $('.button:not(.disabled)').addClass('.disabled, .red'); getVote(pictureID, competitionID); }else { $().toastmessage('showErrorToast', "Error!"); } }); </code></pre> <p>}</p> <p>In the same file:</p> <pre><code>function remVote(pictureID, competitionID){ $.post('vote.php', {pictureID:pictureID, competitionID:competitionID, vote:0}, function(data){ if (data == 'success') { $("#comp_voteButton_"+pictureID).text('Vote picture'); $("#comp_voteButton_"+pictureID).attr("onclick", "addVote(" + pictureID +","+competitionID+","+0+")") $("#comp_voteButton_"+pictureID).removeClass('alreadyVoted'); getVote(pictureID, competitionID); }else { $().toastmessage('showErrorToast', "Error!"); } }); </code></pre> <p>}</p> <p>edit: Here's the link if that makes it easier:</p> <pre><code>&lt;a href="javascript:void(0);" class="button blue small" id="comp_voteButton_&lt;?echo $row['ID']?&gt;" onclick="addVote(&lt;?echo $row['ID']?&gt;, &lt;?echo $id?&gt;, &lt;?echo $vote?&gt;)"&gt;Vote&lt;/a&gt; </code></pre> <p>What I want: On addVote all the other buttons should be set to 'onclick(remVote(ID, compID))' - But I can't do that because both the ID's are not fed into the addVote function.</p> <p>I hope you guys get my question (maybe it isn't possible, or a weird work-around has to be made) - But maybe there's a nifty way of doing it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload