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

SugarCRM Footer Logo Remove

Hi Googler, Let us discuss about how to remove the SugarCRM Footer logo.. You all are aware of the power of the SugarCRM Tool and also must be very eager to remove the footer in order to make it look more professional. So below mentioned are some tricks for removing the footer from SugarCRM Community edition. 1) O pen-modules/Administration/ updater_utils.php Add-exit() ; in between function check_now() and return . By doing this u can remove 'powered by sugar crm' footer logo. 2) Go to modules/Trackers/Tracker.php, line 128, in the 'logPage' function. Drop the 'echo' statement. 3) Now to root(Sugarfolder)\include\mvc\view\sugarview.php and modify the line array(show header => true, show subpanel => true...........and so on) and make the changes to showfooter=>true to showfooter=>false And then enjoy by making it as your own built tool. As per the requests, make a reply and then I'll post the code and path to let you know how to write a cust...
Merry Christmas

Custom Create React App | Best Practices in Typescript | React >16

Custom Create React App | Best Practices in Typescript | React >16 React app has multiple versions now a days, based on the latest typescript implementation using React 16. Here is a code sample if it helps anyone to Kickstart their project or take "inspiration"  GitHub Project This is a simple app to get gists of user. React app, Single Page, Gist User Data download code in local via -  https://github.com/jatinmarwah/React_Sample Master - latest Stable Develop - ongoing check in (might be unstable) execute command on root folder yarn run build:dev OR npm run build: dev Start app with yarn start OR npm start; GO TO: "localhost:8080" Test with any valid gist username App Tested with user "paulirish" Data validation No extensive data validation is done, pagination is not supported(YET), max result received is 30 Basic validations and error handling is done, app level handling and boundaries can be extended Caution As un-authenticated api is being used, GI...