[email protected] Posted September 3, 2011 Share Posted September 3, 2011 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 More sharing options...
voip03 Posted September 3, 2011 Share Posted September 3, 2011 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. Link to comment https://forums.phpfreaks.com/topic/246345-get-value-from-other-page/#findComment-1265064 Share on other sites More sharing options...
[email protected] Posted September 3, 2011 Author Share Posted September 3, 2011 Thank u sooooo much voip03 . You are just too good . Thanks my issue is resolved . Thanks a ton Link to comment https://forums.phpfreaks.com/topic/246345-get-value-from-other-page/#findComment-1265144 Share on other sites More sharing options...
[email protected] Posted September 3, 2011 Author Share Posted September 3, 2011 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; ?> Link to comment https://forums.phpfreaks.com/topic/246345-get-value-from-other-page/#findComment-1265147 Share on other sites More sharing options...
voip03 Posted September 4, 2011 Share Posted September 4, 2011 Please mark it solved. Thank you. Link to comment https://forums.phpfreaks.com/topic/246345-get-value-from-other-page/#findComment-1265302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.