Jump to content

[SOLVED] Php with onClick


chelnov63

Recommended Posts

Hi guys im calling a javascript function and sending it dynamic parameters (which are generated by php) .. i can send one parameter (of Number type) succefully but cant seem to be able to get the syntax right for sending a second parameter(String type) ... when i try to ..the javascript function doesnt even get called and when i rollover the link i can see a javascript error warning at the bottom of the browser...

 

here is the example that works fine:

 

<?php if($totalRows_rsGallery >0){ 
do
{ 
$link = $row_rsGallery['id']; 
echo "<strong>".$row_rsGallery['set_name']."</strong><a href='javascript:void(0)' onclick='showGallery($link)'> View Set</a><br>";  
} 
while ($row_rsGallery = mysql_fetch_assoc($rsGallery)); 
?>
  
  
<script type="text/javascript">        
function showGallery(num)
{
   alert(num);       
}
</script>

 

and here is the code which doesnt even manage to call the function:

 

 

<?php if($totalRows_rsGallery >0){ 
do
{ 
$link = $row_rsGallery['id'];
$setname = $row_rsGallery['setname'];  // this is the second parameter
echo "<strong>".$row_rsGallery['set_name']."</strong><a href='javascript:void(0)' onclick='showGallery($link, $setname)'> View Set</a><br>";  
} 
while ($row_rsGallery = mysql_fetch_assoc($rsGallery)); 
?>
  
  
<script type="text/javascript">        
function showGallery(num, setname)
{
   alert(num);
   alert(setname);       
}
</script>

 

Thanks in advance for your help

Link to comment
https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/
Share on other sites

That would be great if you could..cheers :)

 

 

 

Sorry, I was in the shower.  Here we go:

Javascript requires parameters that are strings to be passed in with quotation marks around them.  This causes a problem with your HTML because you used ' ' around the onClick attribute, which is no good.  You needed to use " " on the onClick string, and escape them so PHP doesn't complain.

 

P.S: I know he could have flipped the quotes and just used \" \" in the javascript call, but w/e.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.