Jump to content

[SOLVED] Javascript variable to php?


Michdd

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.