6 Replies - 2424 Views - Last Post: 09 March 2006 - 01:15 AM Rate Topic: -----

#1 gayatri   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

variable passing from js to php

Posted 08 March 2006 - 10:54 PM

my code goes something like
<?php
$regid=$_GET["reg_id"];
$handle1=mysql_query("select fname,mname,lname from Patient_Registration where registerID='$regid'");
while($row1=mysql_fetch_array($handle1))
{
$fname=$row1["fname"];
$mname=$row1["mname"];
$lname=$row1["lname"];
}

$temp_out = '<script language="javascript">
function dispfun() {
box = document.getElementById("edit-reg_id");
id = box.options[box.selectedIndex].value;
if (id <> "")
{
location.href = "somepathname?reg_id=id";
}

}</script>';

//there is some form display function here which calls dispfun onchange for select option for a form

echo $temp_out;
?>

what i need is how to pass variable reg_id from js to php which i am collecting at top in $_GET
what the syntax shud be
guys plz help
i am only a step behind my goal

thanx in advance

Is This A Good Question/Topic? 0
  • +

Replies To: variable passing from js to php

#2 fyrestorm   User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: variable passing from js to php

Posted 08 March 2006 - 11:07 PM

i'm a bit rusty where php is concerned, but you might want to look up $HTTP_GET_VARS in the PHP documentation and see if that helps...
Was This Post Helpful? 0
  • +
  • -

#3 gayatri   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Re: variable passing from js to php

Posted 08 March 2006 - 11:17 PM

i know how to catch the value in php
what i don't knwo is how to pass it from js
is it the right way what i have used?
but it's not working...
thanx for concern
Was This Post Helpful? 0
  • +
  • -

#4 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: variable passing from js to php

Posted 08 March 2006 - 11:49 PM

There are several ways to do it.

One way is to use iframes who's location/src can be changed with javascript.

That other way it to use the XmlHttpRequest() object stuff.
Was This Post Helpful? 0
  • +
  • -

#5 gayatri   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Re: variable passing from js to php

Posted 09 March 2006 - 12:13 AM

could u plz xplain usage of iframes? i haven't used it before......
in fact i have started using js a few days back

plz lemme know if i am redirecting after select to some url n wanna pass some variable of js, how can i?

"id" is a var in js
let me be specific
"id" is selected index's text
i mean the selected option
i have started with this, n i know it's wrong
location.href = "/main?reg_id=id";

any suggections on var passing in url????

This post has been edited by gayatri: 09 March 2006 - 12:56 AM

Was This Post Helpful? 0
  • +
  • -

#6 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: variable passing from js to php

Posted 09 March 2006 - 01:09 AM

An example made for Firefox.

XMLobj = XmlHttpRequest();
XMLobj.open("get", "path/to/thephp/script.php?reg_id="+someVariableWithTheId, true); //last variable, in this case "true", is for whether or not to run this request asynchronouslyish.
XMLobj.send(null);
XMLobj.onreadystatechange = function handleResponse() {
   if(XMLobj.readyState == 4) {
       response = XMLobj.responseText;
   }
};


Was This Post Helpful? 0
  • +
  • -

#7 gayatri   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Re: variable passing from js to php

Posted 09 March 2006 - 01:15 AM

thanx genious
that's what i needed....
lot many thanx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1