Jump to content


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


passing variables into php

Recommended Posts

how do i pass variables into php from javascript? i've tried

<script language = "javascript"
var valueSelected = frmData.ListLocation.value //this is the value i wan to pass into php
"<?php $test= ?>" valueSelected "<?php ; ?>"

it gives giving me error.

Share this post

Link to post
Share on other sites
You try to mess php and javascript in an improper way. PHP is parsed and interpreted on the server before javascript is being executed on the client's machine, so you can't directly assign a php variable some value that's generated by javascript. You have to do a separate request by using hidden form fields, then assign these fields some values with javascript and finally you have to submit this form using frmData.submit()

Good Luck!

Share this post

Link to post
Share on other sites

check for some terms like AJAX/XMLHttpRequest method,,
I've recently put an example there: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=90550\" target=\"_blank\"]XMLHttpRequest[/a]

So, the script sends javascript values to php using the $_POST method, & php part then updates the database, 'saving changes dynamically', without reloading the page,

You can do the same thing querying and recuperating some values from php -> javascript without reloading the all page, still using some XMLHttpRequest methods,,

Hoping it helps,


Share this post

Link to post
Share on other sites


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.