timmah1 Posted January 5, 2009 Share Posted January 5, 2009 I want to be able to pass a variable to javascript, so that it's available. How is this possible? I have this url=url+"&sports="<?php echo $sport;?> but that don't do anything at all. Can anybody show me the correct way to show php in javascript? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/ Share on other sites More sharing options...
bubbasheeko Posted January 5, 2009 Share Posted January 5, 2009 I don't think that is possible unless there is a form that has been submitted. Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729728 Share on other sites More sharing options...
timmah1 Posted January 5, 2009 Author Share Posted January 5, 2009 It's from a drop-down menu, so it is passed from a form Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729730 Share on other sites More sharing options...
trq Posted January 5, 2009 Share Posted January 5, 2009 That should work depending on the context. Can we see more code? Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729732 Share on other sites More sharing options...
timmah1 Posted January 5, 2009 Author Share Posted January 5, 2009 function showTeam(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="getuser1.php" url=url+"?q1="+str url=url+"&sid1="+Math.random() url=url+"&sports="<?php echo $sport;?> xmlHttp.onreadystatechange=stateChanged1 xmlHttp.open("GET",url,true) xmlHttp.send(null) } I get no error, but no results either Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729733 Share on other sites More sharing options...
trq Posted January 5, 2009 Share Posted January 5, 2009 It should be.... url=url+"&sports=<?php echo $sport;?>" to make it valid javascript. We also might need to see where you actually define this $sport variable. Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729735 Share on other sites More sharing options...
timmah1 Posted January 5, 2009 Author Share Posted January 5, 2009 Sport is being called from a link <a href="post.php?sport=nfl">nfl</a> Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729739 Share on other sites More sharing options...
trq Posted January 5, 2009 Share Posted January 5, 2009 Then it would be $_GET['sport'] not $sport. Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729742 Share on other sites More sharing options...
timmah1 Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks thorpe Link to comment https://forums.phpfreaks.com/topic/139492-solved-the-correct-way-to-pass-this-variable/#findComment-729745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.