Solved

javascript function parameters problem

Posted on 2014-09-11
4
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

626 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