Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery PHP / HTML switch onclick
    primarykey
    data
    text
    <p>This piece of code is somehow not working and I dont know why, im not good at php nor js just trying to make some website.</p> <p>The part that is not working is this favorite button, it works like it has to work but it does not switch to "unfavorite" after click, it only works if u refresh the browser.</p> <p>This is the html that is generated by the php file:</p> <pre><code>&lt;a class="btn" id="fav28" title="Add to Favorites" href="javascript:;" onclick="AddFav('28','fav','add')"&gt; &lt;i class="icon-heart"&gt;&lt;/i&gt; &lt;/a&gt; </code></pre> <p>And this is the js function:</p> <pre><code>function AddFav(id, dothis, dowhat) { $.ajax({ url: ("/process.php?do="+dothis+"&amp;id="+id+"&amp;action="+dowhat) }); if(dowhat == "add"){ document.getElementById(dothis+id).className = 'disabled'; document.getElementById(dothis+id).onclick = another_function document.getElementById(dothis+id).title = 'Remove from Favorites'; }else if(dowhat == "remove"){ document.getElementById(dothis+id).className = 'btn'; document.getElementById(dothis+id).title = 'Add to Favorites'; } } </code></pre> <p>I have tried the </p> <blockquote> <p>document.getElementById(dothis+id).onClick = "AddFav(28,id,remove)";</p> </blockquote> <p>but nothing happens with this, it simply does not change the onclick</p> <p>what it has to do is to change the "onclick" event from</p> <blockquote> <p>onclick="AddFav('28','fav','add')" </p> </blockquote> <p>to </p> <blockquote> <p>onclick="AddFav('28','fav','remove')"</p> </blockquote> <p>Thanks in advance.</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.
    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