473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

pass both variables($q1 and value of select) to js

232 100+
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file

srt.php
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="st.js"></script>
  2. <?php
  3. $q1=$_GET["q1"];
  4.  
  5. require("conn.php");
  6.  
  7. $sql="SELECT distinct(".$q1.")FROM inst";
  8. //echo $sql;
  9. //exit();
  10. $result = mysql_query($sql);
  11.  
  12. ?>
  13.   <input type="hidden" name="q1">
  14. <p>
  15.   <select name="users" onchange="showUser(this.value)">
  16.     <?php 
  17. while($row = mysql_fetch_array($result))
  18.   {
  19.   ?>
  20.     <option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
  21.     <?php   }?>
  22.   </select>
  23.   <?php 
  24. //mysql_close($con);?>

i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file


st.js
Expand|Select|Wrap|Line Numbers
  1. var xmlhttp;
  2.  
  3. function showUser(str)
  4. {
  5. xmlhttp=GetXmlHttpObject();
  6. if (xmlhttp==null)
  7.   {
  8.   alert ("Browser does not support HTTP Request");
  9.   return;
  10.   }
  11. var url="display.php";
  12. url=url+"?q="+str;
  13. url=url+"&sid="+Math.random();
  14. xmlhttp.onreadystatechange=stateChanged;
  15. xmlhttp.open("GET",url,true);
  16. xmlhttp.send(null);
  17. }
  18.  
  19. function stateChanged()
  20. {
  21. if (xmlhttp.readyState==4)
  22. {
  23. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  24. }
  25. }
  26.  
  27. function GetXmlHttpObject()
  28. {
  29. if (window.XMLHttpRequest)
  30.   {
  31.   // code for IE7+, Firefox, Chrome, Opera, Safari
  32.   return new XMLHttpRequest();
  33.   }
  34. if (window.ActiveXObject)
  35.   {
  36.   // code for IE6, IE5
  37.   return new ActiveXObject("Microsoft.XMLHTTP");
  38.   }
  39. return null;
  40. }

display.php

$q1=$_GET["q1"];
$q=$_GET["q"];

kindly help me in doing that
Jul 16 '09 #1
1 2547
acoder
16,027 Expert Mod 8TB
The select value you already have. To pass q1, you will need to first use PHP to generate JavaScript code. As an example:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <?php
  3.     echo "var q1 = '".$q1."';";
  4. ?>
  5. </script>
Of course, you could improve that. Once you have the value in JavaScript, you can pass it to display.php quite easily like "q".
Jul 16 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Al | last post by:
Ref:how to pass value along with click of a button hi,I have created a form that has single button. as follow <asp:button id="btnCallfunction" runat="server" text="func_call" onclick="add_int" />...
3
by: john woo | last post by:
Hi in JSP, it's easy to pass value from java-variable to javascript-variable, like js_function(a) { a=<%java-class.A%> } I'm wondering how is the other way around? I tried
4
by: ruca | last post by:
Hi, How can I pass the values of some variables from page1.aspx to page2.aspx? I try to define some variables in page2 and then when I click a button in page1 it will fill that variables (in...
3
by: pei_world | last post by:
I have a user control: - using LoadControl("MyCtrl.ascx") MyCtrl _mycontrol = (MyCtrl)LoadControl("MyCtrl.ascx") Page.Controls.Add(_mycontrol); _mycontrol.Text it will be loaded when some...
1
by: pei_world | last post by:
I have a user control: - using LoadControl("MyCtrl.ascx") MyCtrl _mycontrol = (MyCtrl)LoadControl("MyCtrl.ascx") Page.Controls.Add(_mycontrol); _mycontrol.Text it will be loaded when some...
3
by: D.P. Roberts | last post by:
I have 3 vbscripts and a vb form with radio buttons corresponding to each script. The form's only purpose is to provide a nice GUI for the user to decide which of the 3 scripts to run. Now, because...
3
by: startsmart | last post by:
Hi This is first time to write and alse it is first time to show this site my problem is i need to pass value from any input type like text for example to hidden field I tried to make a...
1
by: jadeivel756 | last post by:
I BADLY NEED YOUR HELP...... HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C. My problem is that as I exit the...
4
by: jadeivel756 | last post by:
I BADLY NEED YOUR HELP...... HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C. My problem is that as I exit the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.