Jump to content

Recommended Posts

I have some code which displays a icon which adds item to a list. When clicking the image it adds the item but I would like to show some message that this has taken place.

 

The code is:

 

if($params->get('show_add_to_playlist')) $buttons[] = "<a href=\"javascript:add_song_to_playlist(".$song->id.",".$playlist_id.",'s');\">".JHTML::image($jwplayer_root.'buttons/add.png',JText::_('ADD_TO_CURRENT_PLAYLIST'),array("title" => JText::_('ADD_TO_CURRENT_PLAYLIST')) )."</a>";

 

How and where in this code would I add a variable like 'onclick' so I can display a message saying the item has been added?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/275192-onclick-or-similar-message-code/
Share on other sites

Couple of things:

1) This is a javascript question wrapped inside of PHP code.

2) Don't use the "a" tag unless you plan on using it like a link. Instead, use another element like span and style it with a CSS class. This will make it so you don't have to override default behavior of anchors.

3) alert('MyMessage'); will show a message. If you don't want to do that ugly message box, then you'll need to look into some jQuery dialog boxes. http://jqueryui.com/dialog/

How and where in this code would I add a variable like 'onclick' so I can display a message saying the item has been added?

All <a> tags have an onclick attribute you can target in your javascript. Right now, you have set your javascript as the href of your a element, this is the incorrect way to be doing it. Your current code should also be added as part of the onclick element. And really, you should actually have all your javascript in an external file and not inline at all, though I'm suspecting this is beyond your skillset.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.