473,788 Members | 2,810 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
17 2774
acoder
16,027 Recognized Expert Moderator MVP
First of all, decide what format you want to return the output in using ASP. You could return HTML ready for use, or JSON/XML to be parsed. When the response is complete, either set the HTML directly or, if you've returned JSON or XML, parse the response. If you have problems implementing this, post here with your attempt.
Jun 12 '08 #11
vikas251074
198 New Member
I am giving you my complete source code for your kind consideration.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <!--#include file="style.css"-->
  4. <!--#include file="first.asp"-->
  5. <script type="text/javascript">
  6. var xmlHttp
  7.  
  8. function vitem(str){ 
  9.   xmlHttp=GetXmlHttpObject();
  10.   if (xmlHttp==null)  {
  11.     alert ("Your browser does not support AJAX!");
  12.     return;
  13.   } 
  14.   var url="getip.asp";
  15.   url=url+"?q="+str;
  16.   url=url+"&sid="+Math.random();
  17.   xmlHttp.onreadystatechange=stateChanged;
  18.   xmlHttp.open("GET",url,true);
  19.   xmlHttp.send(null);
  20. }
  21.  
  22. function stateChanged() { 
  23.   if (xmlHttp.readyState==4)
  24.     { document.getElementById("txtHint").innerHTML=xmlHttp.responseText;}
  25. }
  26.  
  27. function GetXmlHttpObject(){
  28.   var xmlHttp=null;
  29.   try { xmlHttp=new XMLHttpRequest();  }   // Firefox, Opera 8.0+, Safari
  30.   catch (e){ try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}   // Internet Explorer
  31.   catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
  32. }
  33. return xmlHttp;
  34. }
  35.  
  36. function menu(){
  37.   window.location = "menu.asp";
  38. }
  39. </script>
  40. <html>
  41. <head>
  42. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  43. <title>IP Allocation</title>
  44. </head>
  45. <%
  46. dim conn
  47. dim rs
  48. set conn = server.createobject("ADODB.Connection")
  49. conn.open "Provider=MSDAORA.1; dsn=ipis; Password=ipis; User Id=ipis; Data Source=isap2000;Persist Security Info=True"
  50. set rs = server.createobject("ADODB.Recordset")
  51. %>
  52. <body>
  53. <form name="myform" method="post" action="save_allotment.asp">
  54. <div id="txtHint" style="position:absolute; top:150px; left:300px ">
  55.   <table border="1">
  56.     <tr>
  57.       <th><h2>IP Allotment</h2></th>
  58.     </tr>
  59.     <tr>
  60.       <td>
  61.         <table>
  62.           <tr>
  63.             <td align="right">VLAN Name : </td>
  64.             <td>
  65.               <select name="vlan_name" style="width:150px " onchange="this.form.submit();">
  66. <%              set rs = conn.execute("select vlan_name from vlan_master order by vlan_name")
  67.                 v_lan = rs("vlan_name")
  68.     do while not rs.eof %>
  69.                    <option value="<%=rs("vlan_name")%>"><%=rs("vlan_name")%></option>
  70.                   rs.movenext
  71.                 loop%>
  72.               </select>
  73.             </td>
  74.           </tr>
  75.           <tr>
  76.             <td align="right">Item : </td>
  77.             <td>
  78.               <select name="item" style="width:150px " onchange="vitem(this.value);">
  79. <%              dim v_item
  80.                 set rs = conn.execute("select item, item_desc from network_item order by item_desc")
  81.                 do while not rs.eof
  82.                   if rs("item") = "PC" then%>
  83.                     <option value="<%=rs("item")%>" selected><%=rs("item_desc")%></option>
  84. <%                  v_item=rs("item")
  85.                    else%>
  86.                     <option value="<%=rs("item")%>"><%=rs("item_desc")%></option>
  87. <%                  end if
  88.                   rs.movenext
  89.                 loop%>
  90.               </select>
  91.             </td>
  92.           </tr>
  93.           <tr>
  94. <%          set rs=conn.execute("select ip_address from vlan_detail where item ='"&v_item&"' and vlan_name='"&v_lan&"' and seq_no = (select min(seq_no) from vlan_detail where allotted_to is null and item ='"&v_item&"' and vlan_name='"&v_lan&"')")
  95.             dim v_ip_address
  96.             v_ip_address = rs("ip_address") %>
  97.             <td align="right">IP Address : </td>
  98.             <td align="left">
  99.               <select name="ip_address" style="width:150px ">
  100. <%              set rs=conn.execute("select ip_address from vlan_detail where item ='"&v_item&"' and vlan_name='"&v_lan&"'")
  101.                 do while not rs.eof
  102.                   if rs("ip_address") = v_ip_address then%>
  103.                     <option value="<%=rs("ip_address")%>" selected><%=rs("ip_address")%></option>
  104. <%                  else %>
  105.                     <option value="<%=rs("ip_address")%>"><%=rs("ip_address")%></option>
  106. <%                end if 
  107.                   rs.movenext
  108.                 loop  %>
  109.               </select>
  110.     </td>
  111.           </tr>
  112.           <tr>
  113.             <td align="right">Description : </td>
  114.             <td align="left"><input type="text" name="emp_name" style="width:300px "/></td>
  115.           </tr>
  116.           <tr>
  117.             <td align="right">MAC Address : </td>
  118.             <td align="left"><input type="text" name="mac_addr" style="width:250px "/></td>
  119.           </tr>
  120.         </table>
  121.       </td>
  122.     </tr>
  123.     <tr>
  124.       <td align="center">
  125.         <table>
  126.           <tr>
  127.             <td><input type="button" value="Back" name="back" style="width:100px " onClick="menu();"/></td>
  128.             <td><input type="reset" value="Reset" name="reset" style="width:100px "/></td>
  129.             <td><input type="submit" value="Submit" name="submit" style="width:100px "/></td>
  130.           </tr>
  131.         </table>
  132.       </td>
  133.     </tr>
  134.   </table>
  135. </div>
  136. </form>
  137. </body>
  138. </html>
There is three list in this programme.
1) List of all Virtual Local Area Network VLAN (Maximum 255 connection in single network).
2) List of all items in single VLAN (like routers, computers, printers, switches, server, camera).
3) List of all IP in single item. there is total 255 IP in single VLAN and quota is fixed for each item.

Process should be -
If I select VLAN, then list of items available in that VLAN should display, And if I select items then list of IP should display with blank IP address as selected by default. AJAX method is used to display the list of IP with blank IP as selected. Then I write the name of employee or location to which this IP is allotted.
I am giving you the code of 'getip.asp' which is called in line no. 14.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <title>Untitled Document</title>
  7. </head>
  8. <%
  9. response.expires=-1
  10. sql="select ip_address from vlan_detail where item ="
  11. sql=sql & "'" & request.querystring("q") & "'"
  12.  
  13. set conn=Server.CreateObject("ADODB.Connection")
  14. conn.open "Provider=MSDAORA.1; dsn=ipis; Password=ipis; User ID=ipis; Data Source=isap2000; Persist Security Info=True"
  15. set rs = Server.CreateObject("ADODB.Recordset")
  16. rs.Open sql, conn
  17. %>
  18.   <table border="1">
  19.     <tr>
  20.       <th><h2>IP Allotment</h2></th>
  21.     </tr>
  22.     <tr>
  23.       <td>
  24.         <table>
  25.           <tr>
  26.             <td align="right">VLAN Name : </td>
  27.             <td>
  28.               <select name="vlan_name" style="width:150px " onchange="this.form.submit();">
  29. <%              set rs = conn.execute("select vlan_name from vlan_master order by vlan_name")
  30.                 v_lan = rs("vlan_name")
  31.                 do while not rs.eof 
  32.                     <option value="<%=rs("vlan_name")%>"><%=rs("vlan_name")%></option>
  33. <%                  end if
  34.                   rs.movenext
  35.                 loop %>
  36.               </select>
  37.             </td>
  38.           </tr>
  39.           <tr>
  40.             <td align="right">Item : </td>
  41.             <td>
  42.               <select name="item" style="width:150px " onchange="vitem(this.value);">
  43. <%              dim v_item
  44.                 set rs = conn.execute("select item, item_desc from network_item order by item_desc")
  45.                 do while not rs.eof
  46.                   if rs("item") = request.QueryString("q") then%>
  47.                     <option value="<%=rs("item")%>" selected><%=rs("item_desc")%></option>
  48. <%                  v_item=rs("item")
  49.                    else%>
  50.                     <option value="<%=rs("item")%>"><%=rs("item_desc")%></option>
  51. <%                  end if
  52.                   rs.movenext
  53.                 loop%>
  54.               </select>
  55.             </td>
  56.           </tr>
  57.           <tr>
  58. <%          set rs=conn.execute("select ip_address from vlan_detail where item ='"&v_item&"' and vlan_name='"&v_lan&"' and seq_no = (select min(seq_no) from vlan_detail where allotted_to is null and item ='"&v_item&"' and vlan_name='"&v_lan&"')")
  59.             dim v_ip_address
  60.             v_ip_address = rs("ip_address") %>
  61.             <td align="right">IP Address : </td>
  62.             <td align="left">
  63.               <select name="ip_address" style="width:150px ">
  64. <%              set rs=conn.execute("select ip_address from vlan_detail where item ='"&v_item&"' and vlan_name='"&v_lan&"'")
  65.                 do while not rs.eof
  66.                   if rs("ip_address") = v_ip_address then%>
  67.                     <option value="<%=rs("ip_address")%>" selected><%=rs("ip_address")%></option>
  68. <%                  else %>
  69.                     <option value="<%=rs("ip_address")%>"><%=rs("ip_address")%></option>
  70. <%                end if 
  71.                   rs.movenext
  72.                 loop  %>
  73.               </select>
  74.             </td>
  75.           </tr>
  76.           <tr>
  77.             <td align="right">Description : </td>
  78.             <td align="left"><input type="text" name="emp_name" style="width:300px "/></td>
  79.           </tr>
  80.           <tr>
  81.             <td align="right">MAC Address : </td>
  82.             <td align="left"><input type="text" name="mac_addr" style="width:250px "/></td>
  83.           </tr>
  84.         </table>
  85.       </td>
  86.     </tr>
  87.     <tr>
  88.       <td align="center">
  89.         <table>
  90.           <tr>
  91.             <td><input type="button" value="Back" name="back" style="width:100px " onClick="menu();"/></td>
  92.             <td><input type="reset" value="Reset" name="reset" style="width:100px "/></td>
  93.             <td><input type="submit" value="Submit" name="submit" style="width:100px "/></td>
  94.           </tr>
  95.         </table>
  96.       </td>
  97.     </tr>
  98.   </table>
  99. <body>
  100. </body>
  101. </html>
Problem -
Now what happens in programe is that after selecting items in list it displays list of all IP with blank IP as selected, but it lost VLAN name.

What should I do to avoid this?

Thanks and regards,
Vikas
Jun 13 '08 #12
acoder
16,027 Recognized Expert Moderator MVP
The reason why that happens is that you're replacing the div "txtHint"'s contents with the ASP file. The ASP script that you call should only output what is needed, not the whole page. So if you want the IPs only, return the HTML for the IP select named "ip_address " and set/replace that only.
Jun 13 '08 #13
vikas251074
198 New Member
How can I return the HTML for the IP select named "ip_address " and set/replace that only? Please tell me.

Thanks and regards,
Vikas
Jun 13 '08 #14
acoder
16,027 Recognized Expert Moderator MVP
Look at this quick modification that I've made to getip.asp:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. response.expires=-1
  3. sql="select ip_address from vlan_detail where item ="
  4. sql=sql & "'" & request.querystring("q") & "'"
  5.  
  6. set conn=Server.CreateObject("ADODB.Connection")
  7. conn.open "Provider=MSDAORA.1; dsn=ipis; Password=ipis; User ID=ipis; Data Source=isap2000; Persist Security Info=True"
  8. set rs = Server.CreateObject("ADODB.Recordset")
  9. rs.Open sql, conn
  10.           set rs=conn.execute("select ip_address from vlan_detail where item ='"&v_item&"' and vlan_name='"&v_lan&"' and seq_no = (select min(seq_no) from vlan_detail where allotted_to is null and item ='"&v_item&"' and vlan_name='"&v_lan&"')")
  11.             dim v_ip_address
  12.             v_ip_address = rs("ip_address") %>
  13.               <select name="ip_address" style="width:150px ">
  14. <%              set rs=conn.execute("select ip_address from vlan_detail where item ='"&v_item&"' and vlan_name='"&v_lan&"'")
  15.                 do while not rs.eof
  16.                   if rs("ip_address") = v_ip_address then%>
  17.                     <option value="<%=rs("ip_address")%>" selected><%=rs("ip_address")%></option>
  18. <%                  else %>
  19.                     <option value="<%=rs("ip_address")%>"><%=rs("ip_address")%></option>
  20. <%                end if 
  21.                   rs.movenext
  22.                 loop  %>
  23.               </select>
Only the select is output. You can set the innerHTML of a div containing the select.
Jun 13 '08 #15
vikas251074
198 New Member
I didn't understand what you have done. Please explain me clearly and what to do next? What about the remaining lines of code?

Thanks and regards,
Vikas
Jun 13 '08 #16
acoder
16,027 Recognized Expert Moderator MVP
I've just removed all the extra duplicated code, so that only the select element is output. Run that page directly (without using Ajax) and you'll see what I mean (though check for any syntax errors in the ASP).

What you need to do next is put a div or span around the IP select in the main page and set its innerHTML when the Ajax request is complete/successful. Make sure you give it an ID, so you can access it. Alternatively, just return the options only and set the select element's innerHTML instead.
Jun 13 '08 #17
vikas251074
198 New Member
Okay!
Let us see what happens.
Jun 13 '08 #18

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

Similar topics

19
3573
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
3055
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
5234
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
10364
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
9967
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
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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
6750
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
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.