Michdd Posted May 14, 2009 Share Posted May 14, 2009 I have a simple javascript function that I need to return a value taken from the database. The parameter in the function is the id of the row where I want to return something from. However I can't create the query and get the result because I can't pass the 'id' variable into the php mysql query any way. Link to comment https://forums.phpfreaks.com/topic/158174-solved-javascript-variable-to-php/ Share on other sites More sharing options...
Brian W Posted May 14, 2009 Share Posted May 14, 2009 use javascript's window.location to send the variable via query string... example (not tested): var id = (idk how you get your variable here); window.location='targerpage.php?id=' + id; Link to comment https://forums.phpfreaks.com/topic/158174-solved-javascript-variable-to-php/#findComment-834328 Share on other sites More sharing options...
Michdd Posted May 14, 2009 Author Share Posted May 14, 2009 use javascript's window.location to send the variable via query string... example (not tested): var id = (idk how you get your variable here); window.location='targerpage.php?id=' + id; Does window.location return whatever that page outputs? Edit: I don't think that's what I'm looking for.. Does that just redirect? I could be wrong though. I need a way to get a value from the database so I can update a div with that. Link to comment https://forums.phpfreaks.com/topic/158174-solved-javascript-variable-to-php/#findComment-834360 Share on other sites More sharing options...
Axeia Posted May 14, 2009 Share Posted May 14, 2009 A question for the Ajax part of the forum. And I recommend having a read at w3schools ajax tutorial It's very short and should get you off to a start. Link to comment https://forums.phpfreaks.com/topic/158174-solved-javascript-variable-to-php/#findComment-834374 Share on other sites More sharing options...
Michdd Posted May 14, 2009 Author Share Posted May 14, 2009 A question for the Ajax part of the forum. And I recommend having a read at w3schools ajax tutorial It's very short and should get you off to a start. That seems simple enough. The request that's send to this file in that tutorial is this: xmlhttp.open("GET","time.asp",true); But how would I send other variables to the file? In my case, the id that'll be used in the mysql query. Link to comment https://forums.phpfreaks.com/topic/158174-solved-javascript-variable-to-php/#findComment-834381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.