473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I want to dynamically select second list value based on first list value.

vikas251074
198 New Member
I have create form as below -

Expand|Select|Wrap|Line Numbers
  1.         <table>
  2.           <tr>
  3.             <td align="right">VLAN Name : </td>
  4.             <td>
  5.               <select name="vlan_name" style="width:150px ">
  6. <%              set rs = conn.execute("select vlan_name from vlan_master order by vlan_name")
  7.                 do while not rs.eof%>
  8.                   <option value="<%=rs("vlan_name")%>"><%=rs("vlan_name")%></option>
  9. <%                rs.movenext
  10.                 loop%>
  11.               </select>
  12.             </td>
  13.           </tr>
  14.           <tr>
  15.             <td align="right">Item : </td>
  16.             <td>
  17.               <select name="item" style="width:150px ">
  18. <%              set rs = conn.execute("select item, item_desc from network_item order by item_desc")
  19.                 do while not rs.eof
  20.                   if rs("item") = "PC" then%>
  21.                     <option value="<%=rs("item")%>" selected><%=rs("item_desc")%></option>
  22. <%                else%>
  23.                     <option value="<%=rs("item")%>"><%=rs("item_desc")%></option>
  24. <%                  end if
  25.                   rs.movenext
  26.                 loop%>
  27.               </select>
  28.             </td>
  29.           </tr>
  30.           <tr>
  31.             <td align="right">IP Address : </td>
  32.             <td align="left"><input type="text" name="ip_address" style="width:150px "/></td>
  33.           </tr>
  34.           <tr>
  35.             <td align="right">MIS No : </td>
  36.             <td>
  37.               <select name="mis_no" style="width:250px ">
  38. <%              set rs = conn.execute("select a.mis_no, a.seq_no, a.lot_no, b.item_description from item_procurement_history_dtl a, item_master b where a.status = 'D' and b.item_code = a.item_code order by a.item_code, substr(mis_no, instr(mis_no, '/', -1)+1)")
  39.                 do while not rs.eof%>
  40.                   <option value="<%=rs("mis_no")%>"><%=rs("mis_no")%></option>
  41. <%                rs.movenext
  42.                 loop%>
  43.               </select>
  44.             </td>
  45.           </tr>
  46.           <tr>
  47.             <td align="right">Employee name : </td>
  48.             <td align="left"><input type="text" name="emp_name" style="width:300px "/></td>
  49.           </tr>
  50.         </table>
I am using two table 1) Item_master and 2) IP_Address.
The field of IP_Address is given below
1) Item, IP_Address, EmpName
Here Item and IP_Address field is filled with fixed set of ip addresses and item. And if any ip address is assigned to anybody , then empname is filled, if ip address is released then empname field against that ip address is deleted.

If user select Computer in Item field, then the second field IP Address should be display the first available ip address from table automatically. How can I achieve this?

Thanks and regards,
Vikas
Jun 10 '08 #1
17 2773
acoder
16,027 Recognized Expert Moderator MVP
Note first of all that JavaScript cannot connect to the database directly.

You have two ways (at least) in which you can do this:
1. set all the IP address values in an array using ASP during page load. In the select onchange, you can check which value matches and display the corresponding IP.
2. Use Ajax to connect to the database using an ASP script which returns the IP address to display in the text box.
Jun 10 '08 #2
vikas251074
198 New Member
I will prefer to use 2nd method.
Please give me the code for connection to the oracle database. I know very little about AJAX. I shall oblige you sir

Thanks and regards,
Vikas
Jun 10 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Here's a quick example to get you started. Also check out some of the links in the Offsite Links sticky thread at the top of this forum for some useful beginner tutorials.
Jun 10 '08 #4
vikas251074
198 New Member
To study ajax, I try following code -

This file name is 'ajax.asp'. It has 3 fix list value. When I select a value, it displays details of value. It used a script named 'selectcustomer .js' of which coding is given below this programme.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script src="selectcustomer.js"></script>
  4. </head><body><form> 
  5. Select a Customer:
  6. <select name="customers" onchange="showcustomer(this.value)">
  7. <option value="66788">Sanjay Pandey
  8. <option value="71955">Asis Das
  9. <option value="77581">T.A. Sazid 
  10. </select>
  11. </form><p>
  12. <div id="txtHint"><b>Customer info will be listed here.</b></div>
  13. </p></body>
  14. </html>
This file name is 'selectcustomer .js'
Expand|Select|Wrap|Line Numbers
  1. <%
  2. var xmlHttp
  3.  
  4. function showcustomer(str){ 
  5.   xmlHttp=GetXmlHttpObject();
  6.   if (xmlHttp==null)  {
  7.     alert ("Your browser does not support AJAX!");
  8.     return;
  9.   } 
  10.   var url="getcustomer.asp";
  11.   url=url+"?q="+str;
  12.   url=url+"&sid="+Math.random();
  13.   xmlHttp.onreadystatechange=stateChanged;
  14.   xmlHttp.open("GET",url,true);
  15.   xmlHttp.send(null);
  16. }
  17.  
  18. function stateChanged() { 
  19.   if (xmlHttp.readyState==4)
  20.     { document.getElementById("txtHint").innerHTML=xmlHttp.responseText;}
  21. }
  22.  
  23. function GetXmlHttpObject(){
  24.   var xmlHttp=null;
  25.   try { xmlHttp=new XMLHttpRequest();  }   // Firefox, Opera 8.0+, Safari
  26.   catch (e){ try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}   // Internet Explorer
  27.   catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
  28. }
  29. return xmlHttp;
  30. }
  31. %>
This file name is 'getcustomer.as p'
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <%
  5. response.expires=-1
  6. sql="SELECT * FROM hba_empmast where empno="
  7. sql=sql & "'" & request.querystring("q") & "'"
  8.  
  9. set conn=Server.CreateObject("ADODB.Connection")
  10. conn.open "Provider=MSDAORA.1; dsn=ipis; Password=ipis; User ID=ipis; Data Source=isap2000; Persist Security Info=True"
  11. set rs = Server.CreateObject("ADODB.Recordset")
  12. rs.Open sql, conn
  13.  
  14. response.write("<table>")
  15. do until rs.EOF
  16.   for each x in rs.Fields
  17.     response.write("<tr><td><b>" & x.name & "</b></td>")
  18.     response.write("<td>" & x.value & "</td></tr>")
  19.   next
  20.   rs.MoveNext
  21. loop
  22.  
  23. response.write("</table>")
  24. %>
  25. <body>
  26. </body>
  27. </html>
  28.  
Here problem is that when I select a value from list. details of that value is not displayed. The error message is 'object required' in line no. 6 of 'ajax.asp'.

Thanks and regards,
Vikas
Jun 11 '08 #5
vikas251074
198 New Member
When the content of selectcustomer. js is copied to ajax.asp within <script type="text/javascript"> tag then it display the details on selecting a value. But why not programme run earlier. Can u explain. me?

Thanks and regards,
Vikas
Jun 11 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
I would guess the problem would be the ASP tags <% and %> which are not recognised by JavaScript. Remove them and the linked file should also work.
Jun 11 '08 #7
vikas251074
198 New Member
Yes sir, I did exactly like that, I removed the ASP tag <% %>. but the same. Anyway it works when content of selectcustomer. js is copies to ajax.asp. But my main problem is to display second list value as soon as the first list value is selected. How can I do this?

Thanks and regards,
Vikas
Jun 12 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
Select what in the second list? Can you explain clearly with an example?
Jun 12 '08 #9
vikas251074
198 New Member
Yes sir,
Suppose two list
1) Country
2) State
If country is 'India', then state field should have list of all indian state.
And so on ....

Thanks and regards,
Vikas
Jun 12 '08 #10

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

Similar topics

19
3572
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main form, the subform returns the records based on the two criteria. The criteria used on the main form are values selected in two list boxes. When the user clicks on the first list box (lstCollege), it returns values in the second list box...
1
2662
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be helpful too; but I'm so bad with syntax that specifics will be MOST helpful) SELECT DISTINCT ., . FROM Union Select "<ALL>" , NULL From ;
2
5824
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected WithEvents Fruits As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Results As System.Web.UI.WebControls.Label Protected WithEvents Button1 As System.Web.UI.WebControls.Button … Private Sub Page_Load(ByVal sender As System.Object, ByVal...
2
14748
by: Zlatko Matiæ | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
3
8018
by: Greg Scharlemann | last post by:
I'm not sure the best way to accomplish this... my hunch is with javascript, but I'm not sure if using server side code (PHP) would be easier. I'm adding people to a database. People have a first name, last name, and a undetermined number of Cities and States with which they can be associated. I've got a drop down box that I would like to use to display the number of inputs to allow for city/state entry. I would like to dynamically...
3
3054
by: mso5 | last post by:
Hi, I am trying to build a small form with a list of countries and regions by each country (yes, the classical one), and I'm stuck with it. I'm using AJAX also, and I manage to get the correct value from the selection, but it does not modify the second list based on the first selection. Can anyone tell me what am I doing wrong in this code? I am not a programmer.. Thank you! <script language="javascript" type="text/javascript"> <!--
4
1424
by: ramchml | last post by:
i have two select boxes.based on the selected value in one select box it show the maximum options in the other select box in next page.i used javascript onclick function.for first time it shows correct options in the second select box if i go back and change the value in the 1st select box it shows me the previous value in the 2nd select box,the value not get changed.it is happening only in opera9 all the other browsers its working fine.it seems...
1
5233
by: hello2008 | last post by:
Hi, I have just started coding in PHP. I have coded a web page using HTML, JS, and PHP. An HTML table has to be populated dynamically using the data from the backend. Presently I have 5 records in the backend table so I get 5 HTML-table rows. I have created a session object starting from the login page. The requirement is that as soon as I log in and my request gets forwarded to the foll PHP page I should be seeing the foll. dynamically...
2
1451
by: godkrishna | last post by:
Hi Guys.. I am new to javascript.. pls bare with me :) In my form, i have a table with two columns. first column has checkboxes and second has dropdown lists. On check of each check box.. certain 'options' are addded/removed from its corresponding dropdown list. My problem is, after adding/removing the 'options' dynamically, if I select the newly added option and submit the form, the corresponding value for the newly added option is...
0
9621
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
10264
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
10106
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...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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...
0
6717
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.