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 Quote Link to comment 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? Quote Link to comment 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>"; Quote Link to comment 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!! Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.