Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript to hide <p> areas...

    so basically i have javascript code that i've been trying to write. When "Other" is selected in the form's drop down box, its supposed to show the textarea, otherwise its supposed to stay hidden. I made a seperate HTML page so whomever views this didn't have to scroll through my other javascript code / html / php lol... anyhow here it is

    Code:
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
    </script>
    <script type="text/javascript">
          function update2(f,s,h) {
             var first=$('#'+f).val();
             var hidden=$('#'+h);
                if(first=="other") {
                   hidden.css('display','block');
                else {hidden.css('display','none');}
             }
    </script>
    </head>
    <body bgcolor="#002E2F">
    <form name="Manager" method="post">
    <table border="0" style="background-color:#f4fbee" width="651" height="25" cellpadding="3" cellspacing="3">
    <tr>
    		<td width="651"><font face="verdana" size="2">Please tell us how you were referred to RSIC</font></td>
    	</tr>
    	
    	<tr>
    		<td width="651">
    			<form action="">
    				<select name="referred" id="referred" onchange="update2('referred','othertextarea','otherp');">
    					<option value="select" selected="selected">Select...</option>
    					<option value="AttendRSIC">Attended RSIC Event</option>
    					<option value="AttendIndus">Attended Industry Event</option>
    					<option value="RefRSIC">Referred by RSIC Staff / Board</option>
    					<option value="CurrentRSIC">Current RSIC business partner</option>
    					<option value="RefThird">Referred by a third party that does business with RSIC</option>
    					<option value="other">Other</option>
    				</select>
    			
    		</td
    	</tr>
    	
    	<tr>
    		<td width="651"><font face="verdana" size="2">If you selected "Other" on the previous field, please describe below</font></td>
    	</tr>
    	
    	<tr>
    		<td width="651">
    			<p id="otherp" style="display:none;">
    			<textarea name="othertextarea" id="othertextarea" rows="5" cols="78">
    
    			</textarea>
    			</p>
    		</td>
    	</tr>
    </table>
    Any help is appreciated, thanks everyone!

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    Use Javascript console to check for syntax errors in your code.

    var hidden=$('#'+h);
    if(first=="other") {
    hidden.css('display','block');
    } else {hidden.css('display','none');}
    }
    I am still learning English


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •