Skip to main content

Show hide dropdown in Javascript

Hello Guys,

Again sticking to my basic idea to guiding the users who need very quick, easy and readily available help.

Lets today discuss about how to show hide a dropdown using javascript.

My aim was that I have a dropdown so whenever I select a option another text box should get enabled and disabled respectively and at the same time another dropdown should appear.

So for that I had written small piece of code as below.:
<!--


    <td class="textField" width="30%" align="left" valign="middle" scope="col" >SWF# Available*</td>
    <td class="textField" width="30%" align="left" valign="middle" scope="col" >
   <!-- <input type="radio" name="swfselect" id="swfselect1" value="yes"
onClick="testbutton();"/>
Yes
<input type="radio" name="swfselect" id="swfselect2" value="no"
onClick="testbutton();"/>
No     -->

<select name="swfselect1" id="swfselect1" onchange="testbutton();">
<option value="" selected>Select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>

   
   
 
 
  </tr>
   <tr>
    <td class="textField" width="30%" align="left" valign="middle" scope="col"> SWF Number*</td>
    <td class="textField" width="20%" align="left" valign="middle" scope="col">SWF<input disabled=disabled onblur="email_chk(2);" type="text" size="5" name="swfNo" id="swfNo" maxlength="5"/></td>
    <td class="textField" width="30%" align="left" valign="middle" scope="col" >SWF Details*</td>
     <td class="textField" width="30%" align="left" valign="middle" scope="col" >
  <table cellpadding="0" border="0" width="100%">
  <tr>
 
  <td class="textField" border="0" cellpadding="0">
<select name="gatestatus" id="gatestatus" >
<option value="" selected>Gate Status*</option>
<option value="Planned">Planned</option>
<option value="ready for approval">ready for approval</option>
<option value="Cancelled by customer">Cancelled by customer</option>
<option value="Closed">Closed</option>
<option value="approved">approved</option>
</select>
</td>
   <td class="textField" border="0" cellpadding="0">
  <select name="reasons" id="reasons" style="display:none" >
<option value="" selected>Current Gate*</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<select name="reasons2" id="reasons2" style="display:none" >
<option value="" selected>Current Gate*</option>
<option value="Not Available">Not Available</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
   </td>
 
       </td>
       </tr>
       </table>
         
</td>



-->


As seen above a function is getting triggered whenever a option is selected i:e either Yes or No. The function is as follows

<script language="javascript" type="text/javascript">
function testbutton()
{




if(document.getElementById("swfselect1").value=="Yes")
        {
        document.getElementById("swfNo").disabled=false;
        document.getElementById("swfNo").value="";
        document.getElementById("reasons2").style.display='none';
        document.getElementById("reasons").style.display='block';
       
        }
    if(document.getElementById("swfselect1").value=="No")
        {
        document.getElementById("swfNo").disabled=true;
        document.getElementById("swfNo").value='Awaited';
       document.getElementById("reasons2").style.display='block';
        document.getElementById("reasons").style.display='none';
        }
return false;   
}
</script>






Small piece of Code but interesting to apply.

Let me know if you guys have any comments or opinions.

Comments

Popular posts from this blog

Install SugarCRM - Step by Step Guide

SugarCRM is the market-leading, commercial Open Source customer relationship management (CRM) application. SugarCRM’s Open Source architecture easily adapts to any business environment by offering a more flexible, cost-effective alternative than proprietary applications. It offers a complete CRM system for businesses of all sizes. For a small business SugarCRM can be a huge time and expense saver. It requires minimal technical knowledge to get it installed and the built in web administration console and backup system allow you to feel comfortable that it’s going to keep running. Core SugarCRM functionality includes sales automation, marketing campaigns, support cases, project mgmt, calendaring and more. Built in PHP, supports MySQL and SQL Server allows it that cool functionality LAMP system. We have tested it Windows XP/Vista/2k3 . Step 1: Installing XAMPP on Windows 1. Go to http://www.apachefriends.org/en/xampp-windows.html#641 and click "XAMPP Windows 1.7.1". Download...

STRESS MANAGEMENT

STRESS Stress is an unpleasant fact of life.  We all experience it for various reasons,  and we all try to come up with ways of  coping with it—some with more success  than others. So what exactly is stress  doing to your mind (and body)  when you're staring down a deadline?  And what can you do to power through it? What Stress Actually Does  to You and What You Can  Do About It The real problem with stress is that, for such a well  understood and universally experienced condition,  as a society we deal with it so poorly that it leads  to many of our most lethal illnesses and  long-term health problems. High blood  pressure, heart disease, cancer, stroke,  obesity, and insomnia are all medical  conditions across the spectrum that  can be related to or directly influenced  by high stress as an environmental conditio...

Jquery Carousels

Jquery Carousels we all love carousels they are a fantastic way to give the effects we want our visitors to have, more than that we have multiple components to show like images, links, text etc. There are lot many ways to achieve it, Jquery is ofcourse the best possible option available outside. We all search for lot of ems it can be Jquery Flexslider  or Jcarousel Lite  whatever you choose, customization is required, in this tutorial I am not going to focus on how to install these libraries rather one step ahead, to let you know how these carousels can be called multiple times in the same page having their controls working respectively for each carousel instance. So, lets get started with the HTML <div id="sideRight"> <div id="first">       <!-- Do not change the class and tag type, as this will remain as it is for all the following divisions-->       <p class="containheader">Plans for you <a ...