473,508 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass many variables to ajax

250 Contributor
I want to pass 2 variables in my php page to ajax page in onchange function. Actually this drop down box use in many pages. So I want to pass the page name to ajax page with the user selected value. How can I do that? Please help me..
This is my code.
Expand|Select|Wrap|Line Numbers
  1. ?>
  2.  
  3. <select name="Make"  class="normalTxt" onChange='getMakeIndexPage(this.value); return false; ' id="Make" >
  4. <option value="Select">Select</option>
  5. <?php  $mysql_result1 = mysql_query("SELECT DISTINCT vehicleMake FROM  vehicles");
  6.                         while($row = mysql_fetch_array($mysql_result1)){
  7. foreach( $row AS $key => $val )
  8.     $Make = stripslashes( $val );
  9.     ?>
  10.     <option value=<?php  echo  "'$Make'" ?> ><?php echo "$Make&nbsp;&nbsp;&nbsp;&nbsp&nbsp&nbsp"?>
  11.                 <?php 
  12.     }    
  13.                 ?>
  14. </option>
  15. </select>
  16.  

ajax page
Expand|Select|Wrap|Line Numbers
  1. function getMakeIndexPage(){
  2.  
  3.     var dropdownIndex = document.getElementById('Make').selectedIndex;
  4.     var make = document.getElementById('Make')[dropdownIndex].value;
  5.     var request = GetXmlHttpObject();
  6.     var url="commonFunction.php";
  7.     url=url+"?make="+make+"&S=" +1;
  8.     //alert (url);
  9.     url=url+"&sid="+Math.random();
  10.     request.onreadystatechange=stateChanged;
  11.     request.open("GET",url,true);
  12.     request.send(null);
  13.     function stateChanged()
  14.    {
  15.      if (request.readyState==4)  
  16.         {
  17.  
  18.             document.getElementById("getMake").innerHTML=request.responseText;
  19.  
  20.         }
  21.      }
  22.  
  23. }
  24.  
Sep 15 '11 #1
4 2494
Dormilich
8,658 Recognized Expert Moderator Expert
where do you get the page name from?

additional notes:
compare
Expand|Select|Wrap|Line Numbers
  1. <select name="Make" class="normalTxt" onChange='getMakeIndexPage(this.value); return false;' id="Make">
to
Expand|Select|Wrap|Line Numbers
  1. function getMakeIndexPage(){
  2.  
  3.     var dropdownIndex = document.getElementById('Make').selectedIndex;
  4.     var make = document.getElementById('Make')[dropdownIndex].value;
  5.     // …
wouldn’t it be easier to use
Expand|Select|Wrap|Line Numbers
  1. function getMakeIndexPage(make){
  2.     // …
instead?
Sep 15 '11 #2
ghjk
250 Contributor
I put the page name inside the onchange function. But It doesn't work.

Expand|Select|Wrap|Line Numbers
  1. <select name="Make"  class="normalTxt" onChange='getMakeIndexPage(this.value,index); return false; ' id="Make">
  2.  
and the ajax page
Expand|Select|Wrap|Line Numbers
  1. function getMakeIndexPage(test){
  2.     alert(test);
  3. ...
  4. }
  5.  
Sep 15 '11 #3
Dormilich
8,658 Recognized Expert Moderator Expert
obviously, the first parameter is the dropdown’s value and the second parameter is an (currently) undefined variable named index. additionally, your function ignores the second parameter completely.
Sep 15 '11 #4
deric
92 New Member
you need to enclose the page's name with quotes like
Expand|Select|Wrap|Line Numbers
  1. getMakeIndexPage(this.value, 'index');
without the quotes, javascript will translate it as a variable and will produce an error because it's undefined.

and then add the second parameter on your function to receive the page name.
Sep 16 '11 #5

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

Similar topics

2
2318
by: blurz | last post by:
Hi, would like to know whether I can use ViewState to pass variables from one web page to another. I've been trying do this but all I managed to do is to pass the variable to the target page but...
7
6846
by: Andy Fish | last post by:
Hi, I have a javascript solution where page A launches page B in a second window and then they can pass data between them. That's all well and good. Now say page B wants to navigate to page C...
0
2503
by: Sam | last post by:
I'm wondering if I can pass variables to "TestForm.aspx" with the way I'm using it. It's acting as a jpeg image and looks like: <%@ Page ContentType="image/Jpeg" %> <%@ Import...
5
1901
by: Nate | last post by:
Is there any way within asp.net to pass user defined parameters/variables to an executable? Much thanks. nate
4
1825
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
3207
by: mike | last post by:
Hello, I've got a .aspx page that passes login information to an .asp page using a querystring. The problem is its not secure, the user can see the login information right there and type in...
1
1712
by: sleepingInsomniac | last post by:
I am running Mac OSX 10.4.7 I am building a program that tracks the Total Sales for employees Here is my code, it compiles fine but how do I take a variable from a method and pass it to...
7
2218
by: Gladen Blackshield | last post by:
Hello All! Still very new to PHP and I was wondering about the easiest and simplest way to go about doing something for a project I am working on. I would simply like advice on what I'm asking...
3
2426
by: aalmakto | last post by:
Hey folks, I was wondering if there is anyway to pass down a variable to an include. For example I have 2 pages: -page1.php -page2.php page1.php has a bunch of variables. page1.php also...
3
2554
by: pedjasmek | last post by:
I have one link in the second script that leads to the first one.How can I pass variables from the second script to the first one? I cannot use $_GET $_POST variables because I don't use those...
0
7127
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
7331
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,...
0
7391
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...
1
7054
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...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
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...

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.