chelnov63 Posted August 29, 2008 Share Posted August 29, 2008 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 More sharing options...
BlueSkyIS Posted August 29, 2008 Share Posted August 29, 2008 can we see the code after php execution, to see what's hosing the javascript? Link to comment https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-628782 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 Try: echo "<strong>".$row_rsGallery['set_name']."</strong><a href='javascript:void(0)' onclick=\"showGallery($link, '$setname')\"> View Set</a><br>"; Link to comment https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-628788 Share on other sites More sharing options...
chelnov63 Posted August 29, 2008 Author Share Posted August 29, 2008 Thanks DarkWater and bluesky for your help.. Darkwater that did the trick.. i tried so many combinations which didnt work, your's worked cheers again!! Link to comment https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-628798 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 Please mark this topic as solved. And I'll explain why it worked if you want. Link to comment https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-628802 Share on other sites More sharing options...
chelnov63 Posted August 29, 2008 Author Share Posted August 29, 2008 That would be great if you could..cheers Link to comment https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-628847 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 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 https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-628876 Share on other sites More sharing options...
chelnov63 Posted September 2, 2008 Author Share Posted September 2, 2008 Cheers was off from work .. makes sense .. thanks for your help dark water..appreciate it Link to comment https://forums.phpfreaks.com/topic/121868-solved-php-with-onclick/#findComment-631767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.