Solved

Conditional Enabling/Disabling Textbox using dropdown and visa/versa

Posted on 2011-02-23
6
671 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now