473,406 Members | 2,217 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,406 software developers and data experts.

show input textbox when "other" is selected from xmlhttprequest

This is mostly taken from bits and pieces found on the internet and I need help adjusting it, because I don't understand how it works. I have a form that will display selects based on a select, and this works great. I now want the second select to show <Input Type="text" Name="txtOtherAsset"> only when "other...please specify" is selected, and of course hide it when it's not. Thanks for your help.

My current working functions:
Expand|Select|Wrap|Line Numbers
  1. function showCustomer(str){
  2.     xmlhttp=GetXmlHttpObject();
  3.     if (xmlhttp==null){
  4.         alert ("Your browser does not support AJAX!");
  5.         return;
  6.     }
  7.  
  8.     var url="getclient.asp";
  9.     url=url+"?q="+str;
  10.     url=url+"&sid="+Math.random();
  11.  
  12.     xmlhttp.onreadystatechange=stateChanged;
  13.     xmlhttp.open("GET",url,true);
  14.     xmlhttp.send(null);
  15. }
  16.  
  17. function stateChanged(){
  18.     if (xmlhttp.readyState==4){
  19.         document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  20.     }
  21. }
  22.  
  23. function GetXmlHttpObject(){
  24.     if (window.XMLHttpRequest)    {
  25.         // code for IE7+, Firefox, Chrome, Opera, Safari
  26.         return new XMLHttpRequest();
  27.     }
  28.     if (window.ActiveXObject){
  29.         // code for IE6, IE5
  30.         return new ActiveXObject("Microsoft.XMLHTTP");
  31.     }
  32.     return null;
  33. }
  34.  
  35. function showAsset(str){
  36.     xmlhttpAsset=GetXmlHttpObjectAsset();
  37.     if (xmlhttpAsset==null){
  38.         alert ("Your browser does not support AJAX!");
  39.         return;
  40.     }
  41.  
  42.     var urlAsset="getasset.asp";
  43.     urlAsset=urlAsset+"?a="+str;
  44.     urlAsset=urlAsset+"&sid="+Math.random();
  45.  
  46.     xmlhttpAsset.onreadystatechange=stateChangedAsset;
  47.     xmlhttpAsset.open("GET",urlAsset,true);
  48.     xmlhttpAsset.send(null);
  49. }
  50.  
  51. function stateChangedAsset(){
  52.     if (xmlhttpAsset.readyState==4){
  53.         document.getElementById("txtAsset").innerHTML=xmlhttpAsset.responseText;
  54.     }
  55. }
  56.  
  57. function GetXmlHttpObjectAsset(){
  58.     if (window.XMLHttpRequest)    {
  59.         // code for IE7+, Firefox, Chrome, Opera, Safari
  60.         return new XMLHttpRequest();
  61.     }
  62.     if (window.ActiveXObject){
  63.         // code for IE6, IE5
  64.         return new ActiveXObject("Microsoft.XMLHTTP");
  65.     }
  66.     return null;
  67. }
  68.  
  69. function populate(form){
  70.     var f=form.ClientAsset;
  71.     var selectedOption = f.options[f.selectedIndex].value;
  72.     var strWrkOrdAsset = selectedOption.split(",");
  73.     //form.txtAssetType.value=strWrkOrdAsset [1];
  74.     document.getElementById("txtAssetType").innerHTML=strWrkOrdAsset [1];
  75. }
  76.  
My getAsset.asp
Expand|Select|Wrap|Line Numbers
  1. <SELECT Name="ClientAsset" onChange="populate(this.form)">
  2.                 <OPTION></OPTION>
  3.                 <OPTION>Other...please specify</OPTION>
  4.                 <% Do Until objRSAsset.EOF %>
  5.                     <OPTION Value="<% Response.Write objRSAsset("AssetID") & "," & objRSAsset("Type") %>"><% Response.Write objRSAsset("Asset") %></OPTION>
  6.                     <%
  7.                     objRSAsset.MoveNext
  8.                 Loop
  9.                 %>
  10.             </SELECT>
  11.  
My WorkOrder.asp
Expand|Select|Wrap|Line Numbers
  1. <TD>
  2.                 <SELECT ID="ClientCompany" Name="ClientCompany" onchange="showCustomer(this.value);showAsset(this.value)">
  3.                 <Option>Select Client Company</Option>
  4.                 <% Do While Not objRSCompany.EOF %>
  5.                     <Option Value="<% Response.Write objRSCompany("ClientCompanyID") %>"><% Response.Write objRSCompany("ClientCompanyName") %></Option>
  6.                     <%
  7.                     objRSCompany.MoveNext
  8.                 Loop
  9.                 %>
  10.                 </SELECT>
  11.                 <%
  12.                 objRSCompany.Close
  13.                 Set objRSCompany = Nothing
  14.                 %>
  15.             </TD>
  16.             <TD>Client User</TD>
  17.             <TD>
  18.                 <DIV ID="txtHint">Please select Company first</DIV>
  19.             </TD>
  20.         </TR>
  21.         <TR>
  22.             <TD>Client Asset</TD>
  23.             <TD>
  24.                 <DIV ID="txtAsset">Please select Company first</DIV>
  25.             </TD>
  26.             <TD>Asset Type</TD>
  27.             <TD>
  28.                 <DIV ID="txtAssetType">&nbsp;</DIV>
  29.             </TD>
  30.         </TR>
  31.  
Oct 21 '10 #1
3 2575
I got this to work by running two seperate functions in the getAsset.asp onchange event, where the second function hides and unhides the text box based on what as selected.
Oct 28 '10 #2
Expand|Select|Wrap|Line Numbers
  1. <form name="form1">
  2.     Select Subject ::    <select name="subject">
  3.             <option value="php" onclick="hide_other()">PHP </option>
  4.             <option value="asp"  onclick="hide_other()">ASP </option>
  5.             <option value="html" onclick="hide_other()">HTML </option>    
  6.             <option value="java"  onclick="hide_other()">JAVA</option>    
  7.             <option value="other" onclick="view_other()">Other</option>                            
  8.     </select>
  9.     <input type="text" name="other_suject" id="other_subject" style="display:none;"/>
  10. </form>
  11. <script type="text/javascript">
  12.     function view_other()
  13.     {    
  14.         document.getElementById("other_subject").style.display="block";
  15.     }    
  16.     function hide_other()
  17.     {
  18.         document.getElementById("other_subject").style.display="none";    
  19.     }
  20. </script>
May 17 '12 #3
acoder
16,027 Expert Mod 8TB
An onchange event on the select element makes a lot more sense here.
May 23 '12 #4

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

Similar topics

4
by: j.t.w | last post by:
Hi All. I'm having a problem with my Date of Birth textbox. When I open the ..htm file, the "DoB" textbox is flat with a border. All of my other textboxes are sunken and are yellow. When I...
2
by: cmay | last post by:
I am having a problem with the use of "this". Maybe someone can help me out here, let me know if I am doing this wrong: Lets say I have an object MyObject, which has local variables, and some...
0
by: vladislav.moltchanov | last post by:
I am developing an Access tool for generating an Application MDB for data entry in a "large scale" project. At design stage I would like to keep open these two MDB. One current is generating forms...
2
by: Bill Cohagan | last post by:
I'm trying out ASP.Net and am currently trying to figure out how to refresh the contents of one frame based on a button click in another frame. The button in question is actually a server side...
11
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in...
0
by: SharpCoderMP | last post by:
the Localization property of the Deployment Project allows to select one of only few languages, that is: Chinese, English, French, German, Italian, Japanese, Korean, Portugal, Russian, Spanish....
0
by: Truevision .Net | last post by:
Hi, I have a problem with drag and drop functionality when it comes to dropping pictures from sources like for example internet explorer and the webbrowser control. Dragging and dropping from...
13
by: Kurda Yon | last post by:
Hi, I found one example which defines the addition of two vectors as a method of a class. It looks like that: class Vector: def __add__(self, other): data = for j in range(len(self.data)):...
0
by: jonceramic | last post by:
Hi All, My apologies for asking something that I'm sure has been answered for. But, my google searching can't find a proper set of keywords. I would like to add "New..." or "other..." or...
10
by: dkyadav80 | last post by:
<html> /// here what shoud be java script for: ->when script run then not display all input text field only display selection field. ->when user select other value for institute only this...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.