Jump to content

passing variables into php


aaronlzw_21

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 ; ?>"
</script>

it gives giving me error.
Link to comment
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!
Link to comment
Share on other sites

Hi,,

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,

l8tr,,
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.