Jump to content


Photo

onclick or similar message code


  • Please log in to reply
2 replies to this topic

#1 brownstone4

brownstone4

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 03 March 2013 - 05: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?

 

Thanks.



#2 teynon

teynon

    Advanced Member

  • Members
  • PipPipPip
  • 893 posts

Posted 03 March 2013 - 05: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!
http://www.kickstart...7618755/antroid

http://www.thomaseynon.com

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

haku

    Advanced Member

  • Staff Alumni
  • 6,172 posts

Posted 03 March 2013 - 09:49 PM

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

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com