Hello,

I am currently working on a function that will allow the user to search for an event by date and category.
I've been using the w3schools exercise as an example but i wish to pass 2 pieces of data instead of one and am not sure how to do so.

I'm sure similar posts have been raised before and i apologise if this type of question has already been answered but i could't find it in the forum index.

<FORM name="myForm">
<INPUT type="text" readonly name="MyDate2" value="Click for Calender" onClick="toggleCalendar('MyDate2')"size="15">
Select a Classification:
<select name="Classification2">
<option value="Accountants">Accountants</option>
<option value="Aerial Services">Aerial Services</option>
</select>
<button name="Search" value="radio1" onClick="showupdate(document.myForm.MyDate2.value);">Search Promotions</button>
<br>
</form>
------------------------------------------------------------------
var xmlHttp

function showupdate(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="getupdatePromo.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtupdate").innerHTML=xmlHttp.responseText 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
---------------------------------------------------------------------
i won't bother including the sql page as i don't think that is the problem.
I've tried various combinations such as:
var url="getupdatePromo.php"
url=url+"?q="+str+"?q2="+str2
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)

and such like but it just feels like i'm going around in circles.

Any help would be much appreciated. Even just point me in the direction of a good article or tutorial, i've been banging my head against it for 2 days so i'm very willing to take a few hours to go through a tutorial

many thanks

Tom.

I think i just answered this in the post above this one, but just in case.

url=url+"?q="+str;
url=url+"&q2="+str2;
url=url+"&sid="+Math.random();

However, I would highly recommend you learn jQuery. You'll find ajax requests so much easier.

Just one other thing though i'm a bit sketchy on the syntax to pass 2 variables when the button is clicked.
I thought it was:

<button name="Search" value="radio1" onClick="showupdate(document.myForm.MyDate2.value);(document.myForm.Classification.value);">Search Promotions</button>

thanks.

[while i was looking for examples online i saw a few people mention jQuery.
I want to get this website launched by the end of this week but once it's up i'll have some free time to have a look at jQuery,

Thanks,

Tom.

use onclick="showupdate()"

then in your javascript

var var1 = document.myForm.MyDate2.value;
var var2 = document.myForm.Classification.value;

var url="getupdatePromo.php";
url+="?q="+var1;
url+="?p="+var2;
url+="&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

seems to be working now thx very much u r a legend. Now all i gotta do is work out why my SQL operators < and > are doing the opposite of what they should be lol.

Thanks again and i'll check out that jQuery when i've got a spare minute.

i've changed the code as you said and it seems to be passing the values but i tested the value of $p and it's coming up with ?p=164 instead of just 164.
The search will allow the user to find an entry based on both values not just one or the other in case that makes a big difference.

Also my sql statements seem to be doing the exact opposite of what i ask it to e.g.
with p equalling Monday

$sql4 ="SELECT * FROM Promotions WHERE Monday != '".$p."' ORDER BY PromoID ASC";
$result4 = mysql_query($sql4);

(and it's only returning entries where Monday is empty)

grrrrrrrrrrr

thanks

Finally got it working. You put
url+="&p="+var2;
on the first reply then when i asked about the showupdate() you put it back to

url+="?p="+var2;
which i copied character for character.
It's my own fault for being such a gimbo lol

thanks very much again for all you help u've been a star.

Gald to have helped.
Sorry, I should have highlighted the += thing.
I'm so used to writing it, I did it without thinking.

Sorry to bother you with this again but wold you have any idea as to why this wouldnt work in firefox.
When i click the search button nothing loads and the quantities in the 2 text boxes reset to their load values.

Any help appreciated

Tom

You're saying it works in IE but not firefox?

Might be an idea to post all your code up, my raw ajax is a little rusty as I always use jquery. But I have some older code lying around which I can compare your code to.

Can you try replacing your GetXmlHttpObject function with this one?

function GetXmlHttpObject(handler)
{
var xmlHttp=null;
	if (window.XMLHttpRequest)
	{
		//code for IE7+, Firefox, Chrome, Opera, Safari
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		//code for IE6, IE5
		try
		{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {alert (e.description);}
	}
	return xmlHttp;
}
commented: very helpful thankyou +1

nope that didnt do it.

Im wondering might it be something to do with the submit button i'm using, could it be the syntax as i know firefox is a lot stricter than explorer.
I used the w3schools example in firefox with it using onchange and only one variable being passed and that worked fine. Kept the one variable but called it using a button and it wouldnt do it.

My button looks like

<FORM name="myForm">
<INPUT type="text" readonly name="MyDate2" value="Calender" size="15" onClick="GetDate(this);">

<select name="Classification2">
<option value="Accountants">Accountants</option>
<option value="Aerial Services">Aerial Services</option>
</select>

<button name="Search" value="radio1" onClick="showupdate();">What's On?</button>

<br>

</form>

---then theres my show update function---

function showupdate(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var var1 = document.myForm.MyDate2.value;
var var2 = document.myForm.Classification2.value;
var url="getupdatePromo5.php";
url+="?q="+var1;
url+="&p="+var2;
url+="&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

grateful for any help as always

Tom.

yay its working, it was the button after all did declare it right, thanks.

hey thanks i got it too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.