By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

multiple functions using onchange...

P: 7
JavaScript n00b here.

Here's the code I'm working with:

<select name = "kw1" id = "kw1" size = "6" onchange = "return main_1(this.value)">

------
function main_1(str)
{

genMen_1(str);
genPicts_2(str);

}

Both functions in main_1 cause two different page elements to change simultaneously. The first function is supposed to generate a form element and the second function is supposed to post a picture. However, the result is that both page elements assume the properties of the second function, no matter what it is. So instead of getting a form element and a picture, I just get the same picture across both locations. If I were to reverse the order of the functions, I'd get the form element across both locations.

Any ideas? There's probably just some fundamental thing I'm missing due to my inexperience. I'd really appreciate some guidance.
Jun 21 '07 #1
Share this Question
Share on Google+
5 Replies


dmjpro
100+
P: 2,476
JavaScript n00b here.

Here's the code I'm working with:

<select name = "kw1" id = "kw1" size = "6" onchange = "return main_1(this.value)">

------
function main_1(str)
{

genMen_1(str);
genPicts_2(str);

}

Both functions in main_1 cause two different page elements to change simultaneously. The first function is supposed to generate a form element and the second function is supposed to post a picture. However, the result is that both page elements assume the properties of the second function, no matter what it is. So instead of getting a form element and a picture, I just get the same picture across both locations. If I were to reverse the order of the functions, I'd get the form element across both locations.

Any ideas? There's probably just some fundamental thing I'm missing due to my inexperience. I'd really appreciate some guidance.
WELCOME to TSDN.

So u have three pages right???
And tell me what is the relation between them?
Means .......... Parent - Child Relation.

Kind regards,
Dmjpro.
Jun 21 '07 #2

acoder
Expert Mod 15k+
P: 16,027
Can you give the code for gen_Men1 and gen_Picts2
Jun 21 '07 #3

P: 7
function genMen_1(str)
{

xRequest=GetX();
var url="php/dbrequest.php";
url=url+"?s="+str;
url=url+"&sid="+Math.random();
xRequest.onreadystatechange=swapIt;
xRequest.open("GET",url,true);
xRequest.send(null);
return;

}

function genPicts_2(str)
{

xRequest=GetX();
var url="php/img_gen_2.php";
url=url+"?s="+str;
url=url+"&sid="+Math.random();
xRequest.onreadystatechange=swapPicts;
xRequest.open("GET",url,true);
xRequest.send(null);
return;

}

function swapIt()
{

if (xRequest.readyState==4 || xRequest.readyState=="complete")
{

document.getElementById("menuSwap").innerHTML=xReq uest.responseText;

}
return;

}


function swapPicts()
{

if (xRequest.readyState==4 || xRequest.readyState=="complete")
{

document.getElementById("pictplace").innerHTML=xRe quest.responseText;

}
return;

}


Thanks for your resposnes!
Jun 21 '07 #4

P: 7
I think I got it to do what I want it to do.

Might seem simple to many, but it's all a learning experience. I just had create two separate Ajax requests rather than try and force them through the same request.

Here's how it looks now. I'd still welcome any suggestions:

Expand|Select|Wrap|Line Numbers
  1. function main_1(str)
  2. {
  3.          xRequest=GetX();
  4.         yRequest=GetX();
  5.          if (xRequest==null)         {
  6.                  alert ("Your browser is too old to run this site.");                 return;
  7.  
  8.         }
  9.         var url1="php/dbrequest.php";
  10.         url1=url1+"?s="+str;
  11.         url1=url1+"&sid="+Math.random();
  12.  
  13.         var url2="php/img_gen_2.php";
  14.         url2=url2+"?s="+str;
  15.         url2=url2+"&sid="+Math.random();
  16.  
  17.         xRequest.onreadystatechange=swapIt;
  18.         xRequest.open("GET",url1,true);
  19.         xRequest.send(null);
  20.  
  21.         yRequest.onreadystatechange=swapPicts;
  22.         yRequest.open("GET",url2,true);
  23.         yRequest.send(null);
  24.  
  25.         return;
  26.  
  27.  
  28. }
Jun 21 '07 #5

acoder
Expert Mod 15k+
P: 16,027
I think I got it to do what I want it to do.

Might seem simple to many, but it's all a learning experience. I just had create two separate Ajax requests rather than try and force them through the same request.
Actually, that would be the better way because your previous code was using the same request at the same time which would cause the overwriting. One other possibility would be to wait for one to complete and then make the second request.
Jun 22 '07 #6

Post your reply

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