Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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?
0
joyacv2
Asked:
joyacv2
  • 2
1 Solution
 
Randy PooleCommented:
echo '<li id="mensaje" onClick="lec(''test'')">'.$pa.'</li>';   don't Work

Open in new window

0
 
leakim971PluritechnicianCommented:
echo '<li id="mensaje" onClick="lec(\'' . $pa . '\')">'.$pa.'</li>'; 

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now