javascript & php

  • dheerhot
  • Novice
  • Novice
  • User avatar
  • Posts: 34

Post 3+ Months Ago

hello guys, i had just totally sink to the problem of initializing value of one javascript variable to php variable....

Suppose, i have a form element having id toy, & i get its value as follows...

Code: [ Select ]
var toy=document.getElementById("toy").value


now i want to assign the value of toy to any of php variable, but i m unable to do it,please anyone help..

thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

there's only one way probably
make a redirection using javascript
Code: [ Select ]
 
var toy=document.getElementById("toy").value;
document.location.href='something.php?toyvalue='+toy;
 
  1.  
  2. var toy=document.getElementById("toy").value;
  3. document.location.href='something.php?toyvalue='+toy;
  4.  

and then take the value using get parameter on something.php

Code: [ Select ]
 
$toy_value = $_GET['toyvalue'];
 
  1.  
  2. $toy_value = $_GET['toyvalue'];
  3.  


Note: You may use window.open() instead of document.location, which will be as per your coding requirement
  • jsg
  • Born
  • Born
  • jsg
  • Posts: 2

Post 3+ Months Ago

Also note that something.php should be the name of the current page if you wish to capture the variable in the same page.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 110 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.