javascript function parameters problem

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?
LVL 1
joyacv2Asked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
echo '<li id="mensaje" onClick="lec(\'' . $pa . '\')">'.$pa.'</li>'; 

Open in new window

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

Open in new window

0
 
Ray PaseurCommented:
... 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
 
leakim971PluritechnicianCommented:
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
All Courses

From novice to tech pro — start learning today.