anton_1 Posted August 14, 2011 Share Posted August 14, 2011 Thanks in advance for any help guys <script type="text/javascript"> function showDialog() { $('#box').fadeIn(250); $('#box').fadeTo(0.5); } function hideDialog() { $('#box').fadeOut(250); } </script> <?php $strLink = "<a href='viewTicket.php?id={$row['id']}'>$strName</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 here is the correct method. <script type="text/javascript"> function showDialog() { $('#box').fadeIn(250); $('#box').fadeTo(0.5); } function hideDialog() { $('#box').fadeOut(250); } </script> <?php $strLink = "<a href='viewTicket.php?id=" .$row['id']. "'>" .$strName. "</a>"; ?> it should work Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257093 Share on other sites More sharing options...
anton_1 Posted August 14, 2011 Author Share Posted August 14, 2011 Thanks man. the link is working fine just now I just cant get it to call the onlclick function? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257099 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 whats the code for your onClick function? if you are using onclick to run a php code directly, its not possible. You would need to use ajax for this. Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257102 Share on other sites More sharing options...
anton_1 Posted August 14, 2011 Author Share Posted August 14, 2011 do you have an example please? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257105 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 Considering you appear to be using jQuery anyway you should learn how to use it's selectors and avoid placing onClick events in your markup all together. Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257107 Share on other sites More sharing options...
anton_1 Posted August 14, 2011 Author Share Posted August 14, 2011 I tried using selectors. but was told it was better to use onclick function? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257110 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 I would suggest that who ever told you that didn't know what they where talking about. Selectors are much better as they help separate your code from your markup. Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257112 Share on other sites More sharing options...
anton_1 Posted August 14, 2011 Author Share Posted August 14, 2011 but even still. how would I trigger an event using this $strLink = "<a href='viewTicket.php?id={$row['id']}' class='simpledialog'>$strName</a>"; it doesnt let me use double quotes thanks Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257114 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 $(function() { $('.simpledialog').click(function() { $('#box').fadeIn(250).fadeTo(0.5); } }); Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257120 Share on other sites More sharing options...
anton_1 Posted August 14, 2011 Author Share Posted August 14, 2011 but what about the link? it doesnt let me trigger it? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257123 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 What do you mean it doesn't let you trigger it? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257126 Share on other sites More sharing options...
anton_1 Posted August 14, 2011 Author Share Posted August 14, 2011 $strLink = "<a href='viewTicket.php?id={$row['id']}' class='simpledialog'>$strName</a>"; $(function() { $('.simpledialog').click(function() { $('#box').fadeIn(250).fadeTo(0.5); } }); echoing the class? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257129 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 What? Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257131 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 anton_1, are you trying to use the $strLink = "<a href='viewTicket.php?id={$row['id']}' class='simpledialog'>$strName</a>"; to fade in an id called box? you are already using the href to link it to another page thus the simpledialog function cannot be used. Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257140 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 14, 2011 Share Posted August 14, 2011 anyway, did you use my code? $strLink = "<a href='viewTicket.php?id=" .$row['id']. "'>" .$strName. "</a>"; and it looks like you are using mySql for the $row[] Quote Link to comment https://forums.phpfreaks.com/topic/244745-call-javascript-function-from-php-echo-href/#findComment-1257141 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.