Jump to content


Photo

passing variables into php


  • Please log in to reply
3 replies to this topic

#1 aaronlzw_21

aaronlzw_21
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 04 May 2006 - 03:40 AM

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.

#2 bl0wfish

bl0wfish
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 May 2006 - 06:41 AM

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!

#3 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 04 May 2006 - 08:54 AM

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,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)

#4 aaronlzw_21

aaronlzw_21
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 04 May 2006 - 09:59 AM

okok i got it thanks guyz! i've changed the way i code. it works for now. thanks gurus!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users