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 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    93
    Thanks
    5
    Thanked 0 Times in 0 Posts

    How to hide a text Area?

    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.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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'"....>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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