Jump to content

Get value from other page


jimsanghvi@hotmail.com

Recommended Posts

 

Dear All

 

I am getting the value of element in the form through Ajax . Now my problem is xmlhttp.open("GET","simple2.php?q="+str,true); from simple2.php i want to return the value of $q to main page that is simple1.php

 

So once i get the value of $q on simple1.php then i can do some if condition in php . ie

 

<?php

if ($q =="a" )

{

 

?>

<div class = "abc" >

<input type="text" name="abc" />

 

<?php

 

}

 

?>

 

 

Please have a look at the code below

 

 

Simple1.php

 

<html>

<head>

<script type="text/javascript">

function showCD(str)

{

if (str=="")

  {

  document.getElementById("txtHint").innerHTML="";

  return;

  }

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

    }

  }

xmlhttp.open("GET","simple2.php?q="+str,true);

 

 

 

xmlhttp.send();

}

</script>

</head>

<body>

 

<form>

Select a CD:

<select name="cds" onChange="showCD(this.value)">

<option value="">Select a CD:</option>

<option value="Bob Dylan">Bob Dylan</option>

<option value="Bonnie Tyler">Bonnie Tyler</option>

<option value="Dolly Parton">Dolly Parton</option>

</select>

</form>

 

 

<div id="txtHint"><b>CD info will be listed here...</b></div>

 

 

Simple2.php

 

<?php

$q=$_GET["q"];

 

echo $q;

 

?>

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/246345-get-value-from-other-page/
Share on other sites

Missing variable

  • A variable's purpose is to store information so that it can be used later.
  • it is a good  programming practice to make it crystal clear when a variable is being used for the first time in the program

<script type="text/javascript">
function showCD(str)
{
     var xmlhttp;

PS. please use the code tag(#) next to post the codes.

 

Dear All

 

I am getting the value of element in the form through Ajax . Now my problem is xmlhttp.open("GET","simple2.php?q="+str,true); from simple2.php i want to return the value of $q to main page that is simple1.php

 

So once i get the value of $q on simple1.php then i can do some if condition in php . ie

 

<?php

if ($q =="a" )

{

 

?>

<div class = "abc" >

<input type="text" name="abc" />

 

<?php

 

}

 

?>

 

 

Please have a look at the code below

 

 

Simple1.php

 

<html>

<head>

<script type="text/javascript">

function showCD(str)

{

if (str=="")

  {

  document.getElementById("txtHint").innerHTML="";

  return;

  }

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

    }

  }

xmlhttp.open("GET","simple2.php?q="+str,true);

 

 

 

xmlhttp.send();

}

</script>

</head>

<body>

 

<form>

Select a CD:

<select name="cds" onChange="showCD(this.value)">

<option value="">Select a CD:</option>

<option value="Bob Dylan">Bob Dylan</option>

<option value="Bonnie Tyler">Bonnie Tyler</option>

<option value="Dolly Parton">Dolly Parton</option>

</select>

</form>

 

 

<div id="txtHint"><b>CD info will be listed here...</b></div>

 

 

Simple2.php

 

<?php

$q=$_GET["q"];

 

echo $q;

 

?>

Archived

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

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