Jump to content


onclick or similar message code

  • Please log in to reply
2 replies to this topic

#1 brownstone4

  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 March 2013 - 10:14 PM

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?



#2 teynon

  • Members
  • PipPipPip
  • Advanced Member
  • 898 posts

Posted 03 March 2013 - 10:34 PM

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/

Support my Kickstarter Project!


Vulnerabilities: http://cwe.mitre.org...x.html#Guidance - MySQL.com hacked with SQL Injection - If it happened to them, it can happen to you.

#3 haku

  • Staff Alumni
  • Advanced Member
  • 6,179 posts

Posted 04 March 2013 - 02:49 AM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users