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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.