Hey guys on my site (myroommatesucks.org) I am trying to change the favorite option. Currently we have it as a star when things are unfavorited (upper right corner of the story box) then it changes to "Added to favorites" when you click the star. I am trying to make it so when you click the star all it does it change from one image to another and I am not sure how to do that. I am not the coder, but I believe I found the line to change echo json_encode("Added to favorites"); Is that the correct line? If so what would i need to change it to for it to produce the image which is located images/box-faved.jpg Here is the code in which the current star is located <a class="favoritebtn" href="#favorite-<?=$msg['msg_id']?>"><img src="images/box-fav.jpg" alt="Add to my favorites" width="16" height="16" border="0" align="absmiddle" /></a>
Yes, that is indeed the correct line to change. If you'd take a look at your javascript file, you'd be able to see that the click function calls up the AJAX request function, which then replaces the current content with the content gathered from the requested page. $(targetElement).html(data); Code (markup): Changing echo json_encode("Added to favorites"); Code (markup): To echo json_encode("<img src=\"images/images/box-faved.jpg\" alt=\"Added to favorites\" width=\"16\" height=\"16\" border=\"0\" align=\"absmiddle\" />"); Code (markup): Should work!
Thank you that did work. However it doesn't stay. Meaning after you refresh the page it just goes back to the empty star. I would like it to stay filled in after they favorite it, any idea on how to do that? // Check if user already favorited this story if($user->is_favorite($msg_id)) die(json_encode("Story is already in your favorite list.")); That's the coding for the already favorited list
For that you'd need to add some code above; <a class="favoritebtn" href="#favorite-<?=$msg['msg_id']?>"><img src="images/box-fav.jpg" alt="Add to my favorites" width="16" height="16" border="0" align="absmiddle" /></a> Code (markup): Replace this ^ with; <a class="favoritebtn" href="#favorite-<?=$msg['msg_id']?>"><img src="images/<?=$imgFav?>.jpg" alt="Add to my favorites" width="16" height="16" border="0" align="absmiddle" /></a> Code (markup): Place this above it: if($user->is_favorite($msg_id)){ $imgFav = "box-faved"; }else{ $imgFav = "box-fav"; } Code (markup): This might however not work as I do not know what variables are passed in the file, as I assume it's a completely different file.