Jump to content

onclick or similar message code


brownstone4

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.