Solved

javascript function parameters problem

Posted on 2014-09-11
4
215 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using 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 …

732 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