473,804 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

232 New Member
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 2570
acoder
16,027 Recognized Expert Moderator MVP
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
2187
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" /> Sub func_call(Source As Object, E As EventArgs) ' how to capture the passed variable here end Sub
3
32828
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
1845
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 page2) with values. The proble is that when I call page2 variable values are NULL. Like this: -------------------------------BEGIN CODE-----------------------------------------------
3
1689
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 events fired. so how can I pass value to this user control from aspx template file.
1
1831
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 events fired. so how can I pass value to this user control from aspx template file.
3
5660
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 the scripts are mostly identical to one another, I'd really like to combine them into one script. But I can't for the life of me figure out how to pass a radio button value from a vb form to the script so the appropriate portion of the script is...
3
13494
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 function but it does not work function hdate(){
1
1209
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 function "int reg(struct Member listm, int msize);", the data Ive entered was not stored in the array. #include <stdio.h> #include <conio.h> #include <string.h>
4
2428
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 function "int reg(struct Member listm, int msize);", the data Ive entered was not stored in the array. #include <stdio.h> #include <conio.h> #include <string.h>
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.