...

View Full Version : How to hide a text Area?



coolguyraj
05-29-2006, 04:03 PM
Hi,

I am having a form and below is the code that generates the dropdown list using the data from the database.

-------------------------------------------------------------------------
//function for generating selection list for duration
function loadduration($duration){
$adminemail;
$conn=new oConn;
$sql='SELECT durationagreementid,durationifagreement FROM howard.cda_durationagreement';
$conn->execute('',$sql,'stmt','none','pconnect',$adminemail);
if (!empty($conn->error)) {
echo $conn->error;
include_once('common/footer.req');
exit;
}
$results=$conn->getallrows($conn->stmt);
$records=$conn->nrows;
if ($conn->nrows<1) {
echo 'Duration Agreement Table Empty';
} else {
$i = 0;
while ($i<$records){
if ($duration == $results['DURATIONAGREEMENTID'][$i]){
$selected = "SELECTED";
}

$duration_menu.= '<option value="'.$results['DURATIONAGREEMENTID'][$i].'" '.$selected.'>'.$results['DURATIONIFAGREEMENT'][$i].'</option>';
$i++;
}
}
return $duration_menu;

}
------------------------------------------------------------

Here is the html code corresponding to this function:
<tr>
<td class="header">DURATION :</td>
<td><select class="inputfield" name="cda_duration" id="cda_duration"
<option value="">--------- <?php echo loadduration($duration) ;?>
</select></td>
</tr>
<tr>
<td class="header" nowrap >OTHER:</td>
<td><textarea name="cda_otherinfo" id="cda_otherinfo" rows="3" cols="29" ></textarea></td>

</tr>
--------------------------------------------------------------------------My main aim is to hide the TEXT AREA corresponding to OTHER: and display it only when the last option is selected in the DURATION:dropdown


Could anyone help me with an javascript function that does this job, iam finding it difficult since the dropdown is generated from the database.

Thanks.

Kor
05-29-2006, 04:11 PM
first you have to hide your textarea.
<textarea style="display:none"......>

Now, if you say that your last option could do that job:

<select onchange="this.form['cda_otherinfo'].style.display=this.selectedIndex==this.options.length-1?'block'?'none'"....>

vwphillips
05-29-2006, 04:17 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function Hide(obj,id){
var ta= document.getElementById(id);
ta.style.visibility='visible';
if (obj.selectedIndex==obj.options.length-1){
ta.style.visibility='hidden';
}
}
//-->
</script></head>

<body>
<table>
<tr>
<td class="header">DURATION :</td>
<td>
<select class="inputfield" name="cda_duration" id="cda_duration" onchange="Hide(this,'OTHER');" >
<option value="">Option 1</option>
<option value="">Option 2</option>
<option value="">Option 3</option>
<option value="">Option 4</option>
<option value="">Option 5</option>
</select>
</td>
</tr>
<tr>
<td class="header" nowrap >
<textarea name="OTHER" id="OTHER" rows="3" cols="29" ></textarea>
</td>
<td>
<textarea name="cda_otherinfo" id="cda_otherinfo" rows="3" cols="29" ></textarea>
</td>
</tr>
</table>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum