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

multiple functions using onchange...

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
5 7086
dmjpro
2,476 2GB
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
16,027 Expert Mod 8TB
Can you give the code for gen_Men1 and gen_Picts2
Jun 21 '07 #3
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
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
16,027 Expert Mod 8TB
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

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

Similar topics

6
by: TS | last post by:
Does anyone know if the Mac Browsers (IE5 / Safari) support anonymous functions or lambda functions? Ive been trying to get a site working with the Mac browsers and just cant get it to work. Here...
27
by: Simon Templar | last post by:
Hi, I am trying to introduce a multiple datepicker into a webpage and the problem arises with the second picker. I tried to copy and adapt the code I employed for the first one, renaming the...
3
by: Disco-181 | last post by:
Hi, I have a script which isn't working in Mozilla based browser for some reason. I'm trying to run two functions from the body onload tag and it simply isn't happening. I have a cascading...
3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
1
by: JS | last post by:
I have this form in test.jsp, that consists of 3 drop/down menus (sel1, sel2 and sel3): <body onload="createFirstMenu('sel1');"> <form name="sels" method="post" action=""> <select...
1
by: Abel Chan | last post by:
Hi there, I was trying to write a simple NT services using .NET 2.0 and fileSystemWatcher control. The goal is to poll documents from a watch directory and ftp them to a remote web site. I...
2
by: shankwheat | last post by:
<select name="ddlProfiles" onchange="location.href=frmProfiles.ddlProfiles.options.value;addOption_list()"> Is it possible to call 2 different functions using the onChange event from a...
5
by: steve.chambers | last post by:
I'm sure this q must have been asked before but I'm really struggling to find the answer anywhere so have finally given up and will consult the usenet community - hopefully there's someone out...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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,...
0
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...
0
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
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...
0
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,...

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.