karimali831 Posted May 7, 2011 Share Posted May 7, 2011 Hi! I need help with passing php variable in onclick, can someone please correct code below? Right now the location.href is showing $match_link variable in address bar, it's not reading it. $matchlink = 'onclick="location.href=\'$match_link\';"'; I then echo HTML template... <div class="rankingrow" style="height:28px;background-color:$bg_color" $matchlink> thanks for help. Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/ Share on other sites More sharing options...
Tenaciousmug Posted May 7, 2011 Share Posted May 7, 2011 Try this: $matchlink = "onclick=\"location.href=\"".$match_link."\""; Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212067 Share on other sites More sharing options...
karimali831 Posted May 7, 2011 Author Share Posted May 7, 2011 tried this already and nope, it doesn't do no page load when I click. Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212071 Share on other sites More sharing options...
Tenaciousmug Posted May 7, 2011 Share Posted May 7, 2011 Isn't onclick part of Javascript? Do you have even have a javascript function in there to call that onclick? Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212075 Share on other sites More sharing options...
karimali831 Posted May 7, 2011 Author Share Posted May 7, 2011 no? I don't think I need function to call onclick. never did this before. Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212081 Share on other sites More sharing options...
spiderwell Posted May 7, 2011 Share Posted May 7, 2011 try onClick its case sensitive also you might need onClick='javascript:locaion.blah... Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212087 Share on other sites More sharing options...
karimali831 Posted May 8, 2011 Author Share Posted May 8, 2011 I keep trying but still not working $matchlink = "onClick=\"javascript:location.href=\"".$match_link."\""; anyone please? Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212107 Share on other sites More sharing options...
ldb358 Posted May 8, 2011 Share Posted May 8, 2011 try: $matchlink = "onclick=\"location.href='".$match_link."'\""; Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212113 Share on other sites More sharing options...
spiderwell Posted May 8, 2011 Share Posted May 8, 2011 what do you get when the page executes and you view source? Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212256 Share on other sites More sharing options...
karimali831 Posted May 8, 2011 Author Share Posted May 8, 2011 this is what I see: <div class="rankingrow" style="height:28px;background-color:#4B4B4B" onClick="javascript:location.href=""?site=cup_matches&match=69&laddID=21" "> Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212327 Share on other sites More sharing options...
karimali831 Posted May 8, 2011 Author Share Posted May 8, 2011 Sorry I mean: onClick="location.href="?site=cup_matches&match=69&laddID=21" I got it $match_link = matchlink($dm['matchID'],$ac=0,$tg=0,$redirect=1); $matchlink = "onclick=\"location.href='index.php".$match_link."';\""; <div class="rankingrow" style="height:28px;background-color:$bg_color" $matchlink> thanks anyway for help! Quote Link to comment https://forums.phpfreaks.com/topic/235801-php-in-onclick/#findComment-1212337 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.