How do I pass form data to PHP and return a json string to Javascript?
Does anyone know how pass form values into PHP and still return the data to JavaScript? (For use in Google Charts if anyone is wondering.)
I have an HTML form with 4 radio boxes. I'd like to pass the value of the form so that my PHP request will be modified based on the user's selection.
The results from the PHP request need to be passed to JavaScript for processing.
Answer
Solution:
In the radio button on click event place a javascript function that will perform an XMLHttpRequest to the php page and have the PHP page echo some JSON content that can be decoded in the return of the XHR in Javascript.
Example of such
Answer
Solution:
May this can help you. I think that you must do an Ajax request
You send data to server form your form (here sent are
name
andlocation
). You read this data with javascript with OnSelect and transfert it to your PHP code and, You get backdata
from server into your JavaScript code and you can do what you want with it. Sorry if my solution use JQuery, it is better for cross-browser with less code writing !Answer
Solution:
You could use this line to parse an array into json and use it later in javascript:
More info: http://php.net/manual/en/function.json-encode.php