brownstone4 Posted March 3, 2013 Share Posted March 3, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275192-onclick-or-similar-message-code/ Share on other sites More sharing options...
teynon Posted March 3, 2013 Share Posted March 3, 2013 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/ Quote Link to comment https://forums.phpfreaks.com/topic/275192-onclick-or-similar-message-code/#findComment-1416301 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275192-onclick-or-similar-message-code/#findComment-1416350 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.