473,385 Members | 1,693 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,385 software developers and data experts.

Can't figure out what's wrong with my variable passing

Hi guys, I'm new to PHP and AJAX/JS so I apologize if this is an incredibly obvious error.

I'm in the process of creating multiple listboxes that are chained together for an advanced search form. I have everything working for the ajax and the issue I'm running into is when I try to pass a PHP variable to a JS function. I've searched multiple forums and read multiple posts about this issue but cannot figure out what's going on. I know that everything else is working because if I pass in something besides my PHP variable things come out fine.

The method is called whenever the selection changes:
<select multiple size=5 name="Package" style="width: 15em;" onchange='setPackage($partType, this.value)'>

It's the "$partType" that I'm having issues with. I've tried passing it about a dozen different ways with no luck and I'm not sure how to debug the issue. The function is pretty basic:
function setPackage(str, blah)
{
....
}

Any advice would be appreciated.

-Melinda
Nov 18 '09 #1
4 1671
Dormilich
8,658 Expert Mod 8TB
try
Expand|Select|Wrap|Line Numbers
  1. setPackage(<?php echo $partType; ?>, this.value)
Nov 18 '09 #2
Thanks for the reply. I tried what you suggested and nothing happens when I select something in the listbox. If I change the code to pass in "this.value" for both params it works just fine so I'm not missing anything anywhere else that I know of.

Here's what the javascript looks like:
Expand|Select|Wrap|Line Numbers
  1. function setPackage(str, blah)
  2. {
  3. xmlhttp=GetXmlHttpObject();
  4. if (xmlhttp==null)
  5.   {
  6.   alert ("Browser does not support HTTP Request");
  7.   return;
  8.   }
  9. var url="getVendor.php?";
  10. url=url+"package="+str;
  11. url=url+"&partType="+blah;
  12. url=url+"&sid="+Math.random();
  13. xmlhttp.onreadystatechange=stateChanged2;
  14. xmlhttp.open("GET",url,true);
  15. xmlhttp.send(null);
  16. }
  17.  
  18. function stateChanged2()
  19. {
  20. if (xmlhttp.readyState==4)
  21. {
  22. document.getElementById("vendorSelect").innerHTML=xmlhttp.responseText;
  23. }
  24. }
and the PHP for it:
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('../Connections/dev/admin.php'); ?>
  2. <?php require_once('../Connections/dev/phtdeelib.php'); ?>
  3. <?php
  4. if(isset($_GET['partType'])) {
  5.   echo "PartType = " . $_GET['partType'] . "<br>";
  6. }
  7.  
  8. if(isset($_GET['package'])) {
  9.   echo "Package = " . $_GET['package'] . "<br>";
  10. }
  11.  
  12. ?> 
Is there a way to debug it and see what's wrong with how the variable is being passed?

Thanks in advance!
-Melinda
Nov 18 '09 #3
Dormilich
8,658 Expert Mod 8TB
@MelindaM
If you use Firefox and the Firebug Add-on, you can check the GET/POST requests in the network tab.
Nov 18 '09 #4
I just figured out that I can pass "this.form" instead and then in the method parse out all the values that I need, such as:

Expand|Select|Wrap|Line Numbers
  1. var val1=form.PartType.options[form.PartType.options.selectedIndex].value;
  2. var val2=form.Package.options[form.Package.options.selectedIndex].value;
It only requires passing the one form variable instead of passing multiple values which will be better if this form gets very complex. Hopefully this is a good solution.

I'll probably still try to figure out what's going on the other way using Firebug because I want to understand why the original way won't work.

Thanks for the quick responses guys!
-Melinda
Nov 18 '09 #5

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

Similar topics

2
by: Matt Bradley | last post by:
Can anybody tell what is wrong with this syntax? I'm trying to move some dates from 9 months ago into the present month UDPATE tbl_name SET datetime = DATE_ADD(datetime, INTERVAL 9 MONTH) WHERE...
10
by: Greener | last post by:
Hi, I need help badly. Can you do client-side programming instead of server-side to capture the Browser type info? If this is the case, what's wrong with the following? <script...
5
by: Derek Richards | last post by:
The following syntax is what I found under the Help in Excel's VBA Editor (you may refer to it for the details of each parameter). i specified to open in Write mode (Read Only is false), it...
2
by: marco | last post by:
the problem: I use a typedef inside a class template, than I use this type (dim_v<N1>::Type) to define the argument of a template function f but when I call this function from main, the compiler...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
1
by: jensen bredal | last post by:
******************** DataTable SampleTable = new DataTable(); //DataAdapter fill code in here. DataColumn ExpressionColumn = new DataColumn("Indexer", typeof(System.Int32)); ...
7
by: kishkin | last post by:
Hello everyone! I wanted to write python script with defined function. From that script I wanted to call C module, which in it's turn call defined python function. Sounds simple. But I've got...
1
by: Terry Olsen | last post by:
I use the following code to create an XML string: Private Function CreatePacket(ByVal pt As PacketType) As String Dim xmlDoc As TextWriter = New StringWriter Dim xmlWriter As New...
3
by: shapper | last post by:
Hello, In my Page's VB.NET code I am changing the value of the Profile property NAME. Profile.Name = tbName.Text However, I need to change this property value from a class in my App_Code...
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
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.