Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help showing a select tag if another select tag's option is selected

Posted on 2011-09-14
5
Medium Priority
?
309 Views
Last Modified: 2012-06-21
I need help showing a select tag if another select tag's option is selected. Please see attached code. I'm also using Coldfusion so please disregard the cfif or cf tags.

Basically if the Lead_sourceID (select tag) option is 14 show the other div IntSource.

I hope this makes sense. Also, if there is a jquery way to do this I'm all ears... well in this case eyes :)
<head>

<script type="text/javascript">
window.onload=function() { 
  var sel = document.getElementById("Lead_sourceID"); 
  sel.onchange=function() { 
     document.getElementById("IntSource").style.display=(this.value=="14")?"":"none"; 
  } 
  sel.onchange(); // set the visibility onload too in case of reload 
} 
</script>

</head>

<table>
<tr>
          <td> 
          <!--- SOURCE SELECTS --->
            <select name="Lead_sourceID" tabindex="19" class="required">
                <option value="" <cfif (NOT isDefined("SESSION.LeadSource")) OR SESSION.LeadSource EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gLeadSource">
                <option value="#gLeadSource.pk#"<cfif gLeadSource.pk IS VARIABLES.Lead_SourceID>selected=</cfif>>#Source#</option>
                </cfoutput>
            </select>        
          <!---IntSource Div--->
            <div id="IntSource">
            <select name="Web_SourceID">
                <option value="" <cfif (NOT isDefined("SESSION.Lead_websourceID")) OR SESSION.Lead_websourceID EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gWebSource">
                <option value="#gWebSource.pk#"<cfif gWebSource.pk IS VARIABLES.Lead_websourceID>selected=</cfif>>#websource#</option>
                </cfoutput>
            </select>        
            </div>

          </td>

<tr>

</table>

Open in new window

0
Comment
Question by:jasch2244
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36540845
try this...
 
<head>

<script type="text/javascript">
    function toggleHelp(ele){
        if(ele.value == "14") {
            document.getElementById("IntSource").style.display="Block";
        } else {
            document.getElementById("IntSource").style.display="none";
        }
    }
</script>

</head>

<table>
<tr>
          <td> 
          <!--- SOURCE SELECTS --->
            <select name="Lead_sourceID" tabindex="19" class="required" onChange="javascript:toggleHelp(this);">
                <option value="" <cfif (NOT isDefined("SESSION.LeadSource")) OR SESSION.LeadSource EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gLeadSource">
                <option value="#gLeadSource.pk#"<cfif gLeadSource.pk IS VARIABLES.Lead_SourceID>selected="selected"</cfif>>#Source#</option>
                </cfoutput>
            </select>        
          <!---IntSource Div--->
            <cfif gLeadSource.pk eq "14">
                <cfset stvalue = 'display:block;' />
            <cfelse>
                <cfset stvalue = 'display:none;' />
            </cfif>
            <div id="IntSource" style="#stvalue#">
            <select name="Web_SourceID">
                <option value="" <cfif (NOT isDefined("SESSION.Lead_websourceID")) OR SESSION.Lead_websourceID EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gWebSource">
                <option value="#gWebSource.pk#"<cfif gWebSource.pk IS VARIABLES.Lead_websourceID>selected="selected"</cfif>>#websource#</option>
                </cfoutput>
            </select>        
            </div>

          </td>

<tr>

</table>

Open in new window

0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 36540854
Check this tested

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $('#Lead_sourceID').change(function(){
        $(this).val() == "14" ? $('#IntSource').show() : $('#IntSource').hide();
      });
      
      $('#Lead_sourceID').change();
      
    });
    </script>
</head> 
  <body> 
  <table>
<tr>
          <td> 
          <!--- SOURCE SELECTS --->
            <select name="Lead_sourceID" id="Lead_sourceID" tabindex="19" class="required">
                <option value="" <cfif (NOT isDefined("SESSION.LeadSource")) OR SESSION.LeadSource EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gLeadSource">
                <option value="#gLeadSource.pk#"<cfif gLeadSource.pk IS VARIABLES.Lead_SourceID>selected=</cfif>>#Source#</option>
                </cfoutput>
            </select>        
          <!---IntSource Div--->
            <div id="IntSource">
            <select name="Web_SourceID">
                <option value="" <cfif (NOT isDefined("SESSION.Lead_websourceID")) OR SESSION.Lead_websourceID EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gWebSource">
                <option value="#gWebSource.pk#"<cfif gWebSource.pk IS VARIABLES.Lead_websourceID>selected=</cfif>>#websource#</option>
                </cfoutput>
            </select>        
            </div>

          </td>

<tr>

</table>
</body> 
<html>

Open in new window

0
 
LVL 1

Author Comment

by:jasch2244
ID: 36542804
Wow sorry none of these solutions work. The select tag contained by the div (IntSource) should be hidden when the page loads is not being hidden. Nor is it being toggled in anyway. Not sure where the disconnect is happening as both sets of code make sense. I have included the code I have thus far, notice I commented both solutions (which are both active and I comment out one or the other when testing).

Any thoughts?
<head>
<!---get the latest jquery library--->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

<!---include jquery library and meioMask plugin--->
<script type="text/javascript" src="../Scripts/MaskedInput/jquery.maskedinput-1.2.2.js" charset="utf-8" ></script> 
<script type="text/javascript" >
  jQuery(function($){   
  $("#HomePhone").mask("(999) 999-9999");
  $("#WorkPhone").mask("(999) 999-9999");
  $("#MobilePhone").mask("(999) 999-9999");
  $("#OtherPhone").mask("(999) 999-9999");
  $("#AltPhone").mask("(999) 999-9999");
  $("#ZipCode").mask("99999");
  });
</script> 

<!---CALANDER SCRIPTS--->
	<link type="text/css" href="../Scripts/jquery-ui-1.7.2.custom/development-bundle/themes/custom-theme/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<!--- <script type="text/javascript" src="../Scripts/jquery-1.3.2.js"></script> --->
<script type="text/javascript" src="../Scripts/jquery-ui-1.7.2.custom/development-bundle/ui/ui.core.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.7.2.custom/development-bundle/ui/ui.datepicker.js"></script>
<script type="text/javascript">
	$(function() {
		$("#CreationDate").datepicker({showButtonPanel: true});
	});
</script>

<!---VALIDATION SCRIPTS--->
<script src="../Scripts/Validation/jquery.validate.js" type="text/javascript"></script>
<!-- for styling the form -->
<script src="../Scripts/Validation/lib/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#ContactModify").validate();
});
</script>


<!---SHOW HIDE SELECT FUNCTIONS----------------------------------------------------->

<!---TEST SOLUTION sonawanekiran:--->
<script type="text/javascript">
    $(document).ready(function(){
      $('#Lead_sourceID').change(function(){
        $(this).val() == "14" ? $('#IntSource').show() : $('#IntSource').hide();
      });
      
      $('#Lead_sourceID').change();
      
    });
    </script>

<!---TEST SOLUTION ansudhindra:--->

 <script type="text/javascript">
    function toggleHelp(ele){
        if(ele.value == "14") {
            document.getElementById("IntSource").style.display="Block";
        } else {
            document.getElementById("IntSource").style.display="none";
        }
    }
</script> 

</head>

<body>

<div id="secondaryBKG">
    
  <div id="outerWrapper">
                      
            <div id="header">
              <div id="titleGFX">	</div>
            </div>
            
            <div id="navBar">
              <ul>	
                <li id="listings"><a href="../LISTINGS/Listings.cfm"><span>LISTINGS</span></a></li>
                <li id="buying"><a href="../BUYING/Buying_a_home.cfm"><span>BUYING</span></a></li>
                <li id="selling"><a href="../SELLING/Selling_Value.cfm"><span>SELLING</span></a></li>
                <li id="resources"><a href="../RESOURCES/Resources.cfm"><span>RESOURCES</span></a></li>
                <li id="about"><a href="../ABOUT/About_Jason_Asch.cfm"><span>ABOUT JASON</span></a></li>
                <li id="contact"><a href="../CONTACT/Contact_Jason_Asch.cfm"><span>CONTACT</span></a></li>
                <li id="home"><a href="../index.cfm"><span>HOME PAGE</span></a></li>
              </ul>
            </div>
            
            <div id="contentWrapper">
              <div class="contentHeader"></div>
              
            <div id="crumbs_container">
                <cfinclude template="../CSSMenuWriter/cssmw1/menu.cfml">
            </div>
            
              <div id="contentWide">
                    <div class="sub-contentWide">
<cfform id="ContactModify" name="ContactModify" class="cmxform" method="post" action="Lead_Modifier_Action.cfm">
        <cfif EditMode>
		<!--- Embed primary key as a hidden field --->
        <input type="hidden" name="LeadID" value="<cfoutput>#getLeads.LeadID#</cfoutput>" />
        </cfif>

      <fieldset>
      <legend><cfoutput>#FormTitle#</cfoutput>: <!--- <cfoutput>#getLeads.FirstName#</cfoutput> <cfoutput>#getLeads.LastName#</cfoutput> ---></legend>
      <table width="100%" border="0" align="center">
        <tr>
          <td  scope="row"><div align="right" class="style2">DATE ENTERED:</div></td>
          <td><input name="CreationDate" id="CreationDate" value="<cfoutput>#DateFormat(CreationDate, "mm/dd/yyyy")#</cfoutput>" size="15"></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td width="193" rowspan="15" align="center" valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td width="147"  scope="row"><div align="right" class="style2">FIRST NAME :</div></td>
          <td width="320"><input type="text" name="FirstName" tabindex="2" class="required" id="FirstName" value="<cfoutput>#FirstName#</cfoutput>" size="40" /></td>
          <td   width="320"><div align="right" class="style2">ADDRESS :</div></td>
          <td width="320"><input type="text" name="PropertyAddress" tabindex="13" id="PropertyAddress" value="<cfoutput>#PropertyAddress#</cfoutput>" size="40" /></td>
          </tr>
        <tr>
          <td  scope="row"><div align="right" class="style2">LAST NAME :</div></td>
          <td><input type="text" name="LastName" tabindex="2"  id="LastName" value="<cfoutput>#LastName#</cfoutput>" size="40" /></td>
          <td  ><div align="right" class="style2">CITY :</div></td>
          <td><input type="text" name="City" tabindex="14" id="City" value="<cfoutput>#City#</cfoutput>" size="40" /></td>
        </tr>
        <tr>
          <td  class="style2" scope="row"><div align="right">SECONDARY FIRST :</div></td>
          <td><input type="text" name="Secondary_first" tabindex="3" id="LastName2" value="<cfoutput>#Secondary_first#</cfoutput>" size="40" /></td>
          <td  ><div align="right" class="style2">STATE :</div></td>
          <td><input type="text" name="State" tabindex="15" id="State" value="<cfoutput>#State#</cfoutput>" size="10" /></td>
        </tr>
        <tr>
          <td  class="style2" scope="row"><div align="right">SECONDARY LAST :</div></td>
          <td><input type="text" name="Secondary_last" tabindex="4"  id="LastName3" value="<cfoutput>#Secondary_last#</cfoutput>" size="40" /></td>
          <td  ><div align="right" class="style2">ZIP CODE :</div></td>
          <td><input type="text" name="ZipCode" tabindex="16" alt="integer"  id="ZipCode" value="<cfoutput>#ZipCode#</cfoutput>" size="10" /></td>
        </tr>
        <tr>
          <td  scope="row"><div align="right" class="style2">COMPANY :</div></td>
          <td><input type="text" name="Company" tabindex="5" id="Company" value="<cfoutput>#Company#</cfoutput>" size="40" /></td>
          <td  ><div align="right" class="style2">E-MAIL ADDRESS :</div></td>
          <td><input type="text" name="EmailAddress" tabindex="17" class="required email" id="email" value="<cfoutput>#EmailAddress#</cfoutput>" size="40" /></td>
        </tr>
        <tr>
          <td  scope="row"><div align="right" class="style2">HOME PHONE :</div></td>
          <td><input type="text" name="HomePhone" tabindex="6" id="HomePhone" value="<cfoutput>#HomePhone#</cfoutput>" size="40" alt="phone-us" /></td>
          <td ><div align="right" class="style2">SECOND E-MAIL :</div></td>
          <td><input type="text" name="SecondEmail" tabindex="18" id="EmailAddress3" value="<cfoutput>#SecondEmail#</cfoutput>" size="40" /></td>
        </tr>
        <tr>
          <td  scope="row"><div align="right" class="style2">WORK PHONE :</div></td>
          <td><input type="text" name="WorkPhone" tabindex="7" id="WorkPhone" value="<cfoutput>#WorkPhone#</cfoutput>" size="40" alt="phone-us" /></td>
          <td  ><div align="right" class="style2">WEBSITE :</div></td>
          <td><input type="text" name="Website" tabindex="18" class="url" id="EmailAddress2" value="<cfoutput>#Website#</cfoutput>" size="40" /></td>
        </tr>
        <tr>
          <td  scope="row"><div align="right" class="style2">MOBILE PHONE :</div></td>
          <td><input type="text" name="MobilePhone" tabindex="8" id="MobilePhone" value="<cfoutput>#MobilePhone#</cfoutput>" size="40" alt="phone-us"  /></td>
          <td><div align="right" class="style2">LEAD SOURCE :</div></td>
          <td> 
          <!---------------------------------------------- SOURCE SELECTS ------------------------------------------->
            <select name="Lead_sourceID" tabindex="19" class="required">
                <option value="" <cfif (NOT isDefined("SESSION.LeadSource")) OR SESSION.LeadSource EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gLeadSource">
                <option value="#gLeadSource.pk#"<cfif gLeadSource.pk IS VARIABLES.Lead_SourceID>selected=</cfif>>#Source#</option>
                </cfoutput>
            </select>        
          <!---------------------------------------------IntSource Div----------------------------------------------->
            <div id="IntSource">
            <select name="Web_SourceID">
                <option value="" <cfif (NOT isDefined("SESSION.Lead_websourceID")) OR SESSION.Lead_websourceID EQ "">selected="selected"</cfif>></option>             
                <cfoutput query="gWebSource">
                <option value="#gWebSource.pk#"<cfif gWebSource.pk IS VARIABLES.Lead_websourceID>selected=</cfif>>#websource#</option>
                </cfoutput>
            </select>        
            </div>

          </td>
        </tr>
        <tr>
          <td  scope="row"><div align="right" ><input type="text" name="OtherPhoneLabel" tabindex="9" id="OtherPhoneLabel" value="<cfoutput>#OtherPhoneLabel#</cfoutput>" size="15" /></div></td>
          <td><input type="text" name="OtherPhone" tabindex="10" id="OtherPhone" value="<cfoutput>#OtherPhone#</cfoutput>" size="40" alt="phone-us"  /></td>
          <td  ><div align="right" class="style2">LEAD TYPE :</div></td>
          <td> <select name="Lead_typeID" class="required" tabindex="20">
            <option value="" <cfif (NOT isDefined("SESSION.Lead_typeID")) OR SESSION.Lead_typeID EQ "" >selected="selected"</cfif>></option>
            <cfoutput query="gLeadType">
              <option value="#gLeadType.id#"<cfif gLeadType.id IS VARIABLES.Lead_typeID>selected</cfif>>#type#</option>
            </cfoutput>
          </select>    </td>
        </tr>
        <tr>
          <td  scope="row"><div align="right">
            <input type="text" name="AltPhoneLabel" tabindex="11" id="AltPhoneLabel" value="<cfoutput>#AltPhoneLabel#</cfoutput>" size="15" />
          </div></td>
          <td><input type="text" name="AltPhone" tabindex="12" id="AltPhone" value="<cfoutput>#AltPhone#</cfoutput>" size="40" alt="phone-us"/></td>
          <td ><div align="right" class="style2">LEAD PRIORITY :</div></td>
          <td>
                <select name="Lead_priorityID" tabindex="21">
                  <option value="" <cfif (NOT isDefined("SESSION.Lead_priorityID")) OR SESSION.Lead_priorityID EQ "" >selected="selected"</cfif>></option>
                  <cfoutput query="gLeadPriority">
                    <option value="#gLeadPriority.id#"<cfif gLeadPriority.id IS VARIABLES.Lead_priorityID>selected</cfif>>#Group#</option>
                    </cfoutput>
                </select>
          </td>
        </tr>
        <tr>
          <td valign="middle"  scope="row"></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"  scope="row"><div align="right" class="style2">NOTES :</div></td>
          <td colspan="3"><textarea name="Notes" cols="80" rows="3" id="Notes" tabindex="22" ><cfoutput>#Notes#</cfoutput></textarea></td>
          </tr>
        
        
       <tr>
         <td colspan="4" scope="row"><div align="center">
           <input type="submit" class="buttons submit" value="Submit">
         </div></td>
         </tr>
      </table>     
      </fieldset>  
    </cfform>                    
                </div>
                    <br class="clearFloat" />               
               
              </div>
            </div>
            <div id="footerWide"></div>
  </div>
</div>
</body>
</html>

Open in new window

0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36542836
You haven't modify your code correctly.
This <select name="Lead_sourceID" tabindex="19" class="required"> should be
<select name="Lead_sourceID" id="Lead_sourceID" tabindex="19" class="required">
0
 
LVL 1

Author Closing Comment

by:jasch2244
ID: 36543110
Awesome... It works perfect now. Thank you
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

604 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