473,624 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic drop down boxes..

5 New Member
Hi,

am trying to create dynamic drop down boxes..
there are 3 drop down boxes.

The second drop down box elements are to be update based on the selection made in the first drop down box (selecting an element on the first drop down box calls a getData.jsp file which returns the result.)

the third drop down box elements are to be update based on the selection made in the second drop down box (selecting an element on the second drop down box calls a getData.jsp file which returns the result.)

Can you help me with this....?
Oct 14 '07 #1
3 2542
acoder
16,027 Recognized Expert Moderator MVP
I assume that you're going to use Ajax for this. What code do you have so far?
Oct 14 '07 #2
amcoldspy
5 New Member
I assume that you're going to use Ajax for this. What code do you have so far?

JavaScript part

Expand|Select|Wrap|Line Numbers
  1. var xmlHttp
  2. var hint_about
  3.  
  4. function setAbout(stri)
  5. {
  6. hint_about = stri;
  7. }
  8.  
  9. function getAbout()
  10. {
  11. return hint_about;
  12. }
  13.  
  14. function showHint(st, lin, about)
  15. {
  16. if (st.length==0)
  17.   { 
  18.   document.getElementById(about).innerHTML="";
  19.   return;
  20.   }
  21. xmlHttp=GetXmlHttpObject()
  22. if (xmlHttp==null)
  23.   {
  24.   alert ("Your browser does not support AJAX!");
  25.   return;
  26.   } 
  27. var url=lin;
  28. url=url+"?q="+st;
  29. url=url+"&sid="+Math.random();
  30. xmlHttp.onreadystatechange=stateChanged;
  31. xmlHttp.open("GET",url,true);
  32. xmlHttp.send(null);
  33.  
  34. function stateChanged() 
  35. if (xmlHttp.readyState==4)
  36. var temp = getAbout();
  37. document.getElementById(temp).innerHTML=xmlHttp.responseText;
  38. }
  39. }
  40.  
  41. function GetXmlHttpObject()
  42. {
  43. var xmlHttp=null;
  44. try
  45.   {
  46.   // Firefox, Opera 8.0+, Safari
  47.   xmlHttp=new XMLHttpRequest();
  48.   }
  49. catch (e)
  50.   {
  51.   // Internet Explorer
  52.   try
  53.     {
  54.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  55.     }
  56.   catch (e)
  57.     {
  58.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  59.     }
  60.   }
  61. return xmlHttp;
  62. }
  63.  
  64.  
  65. function elementExchange(eleID)
  66. {
  67. loadArray();
  68.  
  69. var i =0
  70. for(i=0;i<jsArray.length;i++)
  71. {
  72. var optn = document.createElement("OPTION");
  73. optn.value=jsArray[i]
  74. optn.text=jsArray[i]
  75. document.getElementById(eleID).options.add(optn)
  76. } // end of for
  77.  
  78. } // end of elementExchange()
  79.  
  80.  

Below is where it is supposed to be updated

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.                 <td align="center">
  3.  
  4.                     <select size="1" name="asset_type1" onclick="setAbout('temp_choice'); showHint(this.value, '/asset/jsps/ajaxGetMake.jsp'); elementExchange('make1');"><%out.print(opts);%></select></td>
  5.                 <td align="center"> 
  6.                     <select size="1" name="make1" onclick="showHint(this.value, '/asset/jsps/ajaxGetModel.jsp'); setAbout('model1');"></select></td>
  7.                 <td align="center"> 
  8.                     <select size="1" name="model1" onclick="showHint(this.value, '/asset/jsps/ajaxGetAssetTag.jsp'); setAbout('asset_tag1');"></select></td>
  9.                 <td align="center"><select size="1" name="asset_tag1" onclick="document.asset.asset_tag2.value = this.value;"></select></td>
  10.             </tr>
  11.  
  12.  
  13.  
  14. <form name="temp_form">
  15. <div id='temp_choice' style='display:none'></div>
  16. </form>
  17.  
Oct 18 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
If the response from the server-side returns the options as HTML, just use innerHTML to set the options. If not, parse the response to get the options andset them. Don't only use the add method with one parameter. That only works in IE. See this link.

Once you have one working, we'll worry about the third dropdown box.
Oct 18 '07 #4

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

Similar topics

4
6294
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
2
12354
by: Michael | last post by:
Need some help trying to read values from web controls - specifically *finding* the controls (like a drop down list) - that are added dynamically added within an asp:panel control. The page contains multiple panels within the form. The panels appear at different times - for our argument, let's say panel 1 appears first, users clicks a submit button and then panel 1 disappears and panel 2 appears, etc. When clicks on the submit button...
4
3796
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build the where clause of a sql string to send to SQL 2000 for a data set. Currenly I check each control with an IF statement to determine if something is filled in. If there is I begin building the where clause. Below is what I have done (and it...
2
12609
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will select any skill in 1st drop down list then i'll select % of this skill in the 2nd list box , based on the percentage i've selected in the 2nd list box it has to display 2 sets of drop down list boxes at run time one for selecting skill and
2
1970
by: taras.di | last post by:
Hi everyone, I've been reading up on how to create a drop down box who's context is dynamically produced based on the value of a previous select box. I've read a lot about some of the browsers not properly readjusting the width of a dynamically produced drop down box, and some browsers having problems adjusting the height and widths (most notably NN). Most solutions involve manually refreshing the browser window and/or padding the...
5
2628
by: dynamitez | last post by:
Hi there, I need some help! I want to create 2 dependent dynamic drop down boxes which choices of box 2 depends on the choice chosen from box 1. Ex. Box1 -western -eastern Box2 (If western is chosen)
1
3456
by: bytesFTW99 | last post by:
I have been struggling with this for some time can anyone help out? just trying to have 3 dropdown boxes that fill depending on what is selected, then in some cases click a button and have the second set of 3 dropdown boxes be filled with the same values. thank you <head> <SCRIPT LANGUAGE="JavaScript" type="text/javascript"> var firstChoice2 = 0; var secondChoice2 = 0;
3
2802
by: happyman992 | last post by:
Hi, I have 2 questions. First, I am building a form with multiple drop down boxes. The options of the second drop down box will depend on what the user chooses on the first, options of the third drop down box depend on what they choose on the second, etc. The values of each option are inside a database which I can query for and put into a php array. I am wondering what is the easiest way to build this. Second, when this form is...
0
8240
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8482
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
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 we have to send another system

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.