Solved

javascript function parameters problem

Posted on 2014-09-11
4
213 Views
Last Modified: 2014-09-12
Hi,

echo '<li id="mensaje" onClick="lec()">'.$pa.'</li>';   Works

echo '<li id="mensaje" onClick="lec("test")">'.$pa.'</li>';   don't Work

give me an unexpected token } error, any idea?
0
Comment
Question by:joyacv2
  • 2
4 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40317738
echo '<li id="mensaje" onClick="lec(''test'')">'.$pa.'</li>';   don't Work

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40317756
echo '<li id="mensaje" onClick="lec(\'' . $pa . '\')">'.$pa.'</li>'; 

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40317891
... onClick="lec("test")"> fails because JavaScript is confused by the nested quote marks.  Either escape the quotes or choose a different version of the quote mark.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40319383
also, as you've jQuery in the box, you do it like this instead :
jQuery("#mensaje").on("click", function() { // jQuery -> $
      var param = $(this).data("param");
      lec(param);
});

Open in new window


with :
echo '<li id="mensaje" data-param="' . $pa . '">'.$pa.'</li>'; 

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question