Link to home
Start Free TrialLog in
Avatar of mmassy

asked on

Javascript and ASP.Net

I'm creating a Web App using Visual Studio 2003. I have a Web Form containing 2 dropdownlists, say drpList1, drpList2.  On page load drpList2 is not visible (using drpList2.Visible = false). I'm using a javascript onchange event for drpList1. When I select a value from drpList1 and will like drpList2 to be visible. Any ideas on how to do this using javascript?
Avatar of NeoDiffusion
Flag of France image


Below a raw solution. For more precise help, please post the HTML code of your form (the one from your browser) ? I'm not sure how ASP.Net converts "drpList2.Visible = false" into HTML code.

It's however probably through a div, so could be done through something like:
... onchange="var a = document.getElementById('drpList2'); = 'block';" ...
assuming the div has an id called 'drpList2', like in
<div style="display:none;" id="drpList2">

Analyzing the "source" of your page (from your browser) will help you fine-tuning.

So in order to comlpete Werner's solution:

What ASP.Net does for drpList2.Visisble=false is it doesn't add it to the HTML! So you have to remove that line from your code. Then put this second dropdown inside a div, and manually add the      style="display:none;" id="drpList2"     attributes to its code. Then follow what Werner said and voilla!
Avatar of huji
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmassy


Thanks, guys that worked. Do I do the same for a check box?
generally speaking: yes. But if you want a more detailed answer, tell me what you want to do, and I will provide you with some code.