...

View Full Version : javascript to hide <p> areas...



bedlam
11-18-2011, 04:48 PM
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


<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!

Amphiluke
11-18-2011, 05:02 PM
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');}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum