Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Conditional Enabling/Disabling Textbox using dropdown and visa/versa

Posted on 2011-02-23
6
Medium Priority
?
684 Views
Last Modified: 2012-05-11
I've reached an impasse and need some help to make it over this hump. I'm working on an asp page that will have conditional validating of a textbox and a dropdown list. I created a function that looks like this:

<script LANGUAGE="javascript">
    function Toggle_AcctNumber(){
      
      if(document.Getparms.DropLineItem.value != [NOI])
        document.GetParms.AcctNumber".disabled="true";
     
      else if(document.Getparms.AcctNumber.value.length != 0)
              document.GetParms.DropLineItem.disabled=true;
    }
  </script>

and here is how i call that function in the dropdown and textbox....

 <SELECT name="DropLineItem" id=DropLineItem onclick = "Toggle_AcctNumber();" size="1" style="HEIGHT: 22px; WIDTH: 320px">


<input type="text" id="AcctNumber" name="AcctNumber" onchange = "Toggle_AcctNumber();">

can anyone tell me what i'm doing wrong? Thanks....
0
Comment
Question by:khasm1972
6 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34961939
Yes, you need to view your page source. ASP prefixes additional text to all web controls at render/run time. So view source, get the name that ASP generated and replace .DropLineItem.Disabled with the full name you found in the rendered HTML. Do this for both of your document.GetParms calls and you should be back on track.
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34961948
Now all you should replace is the .DropLineItem. with .{NEWNAME}. and the same for the other control.
0
 

Author Comment

by:khasm1972
ID: 34962067
The control names look the same to me when I view the page source.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1000 total points
ID: 34962184
replace it with

<script LANGUAGE="javascript">
    function Toggle_AcctNumber(){
     
      if(document.getElementById("DropLineItem").value != "NOI")
        document.getElementById("AcctNumber").disabled="true";
     
      else if(document.getElementById("AcctNumber").value.length != 0)
              document.getElementById("DropLineItem").disabled=true;
    }
  </script>
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34962237
I think rawinnlnx9 is confusing ASP with ASP.Net.

The following works for me, try comparing it with what you have:
<html>
<head>
   <script type="text/javascript">
     function Toggle_AcctNumber()
     {
        if (document.GetParms.DropLineItem.value != 'NOI')
          document.GetParms.AcctNumber.disabled = true;
        else if (document.GetParms.AcctNumber.value.length != 0)
          document.GetParms.DropLineItem.disabled = true;
     }
   </script>
</head>
<body>


    <form name="GetParms" id="GetParms">
      <select name="DropLineItem" id="DropLineItem" onclick="Toggle_AcctNumber();">
         <option value="NOI">NOI</option>
         <option value="One">One</option>
      </select>

      <input type="text" id="AcctNumber" name="AcctNumber" onchange="Toggle_AcctNumber();" />
    </form>

</body>
</html>

Open in new window

0
 

Author Comment

by:khasm1972
ID: 34962282
ok...i still have some kinks to run out of it but at least it is working now.....
thanks gurvinder372....
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question