Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Drop Down Menu with Javascript


Message #1 by anne.do@c... on Wed, 7 Aug 2002 18:48:43
Anne,

Apparently you can't attach stuff with this newsgroup.  Here's the code in
toto:
===============================
<html>
<head><title>Whatever</title>

<script language="javascript">

function VisHid_OtherRoom (form)
{
   var nIndex = form.Room.selectedIndex;

   if ( nIndex == 4 )
      ID_Name.style.visibility = "visible";
   else
      {
      ID_Name.style.visibility = "hidden";
      form.Chosen_Room.value = form.Room.options[nIndex].value;
      }

   return;
}

function SwapOther (form)
{
   form.Chosen_Room.value = form.Other_Room.value;
   return;
}

</script>

<FORM NAME = "getdata" ACTION = "test.htm" METHOD = "POST"
enctype="application/x-www-form-urlencoded" >
<table>
   <tr>
      <td align=right>Choose a room</td>
      <td>
         <SELECT NAME="Room" onClick="javascript:VisHid_OtherRoom
(this.form);">
            <OPTION value="Main Conference Room" >Main Conference Room
            <OPTION value="Alexandria Team Room" >Alexandria Team Room
            <OPTION value="Arlington Team Room"  >Arlington Team Room
            <OPTION value="Baltimore Team Room"  >Baltimore Team Room
            <OPTION value="Other Room"           >Other Room
         </SELECT>
      </td>
   </tr>

   <tr ID=ID_Name STYLE="visibility:hidden">
      <td align=right width=350>What is the Other Room called? </td>
      <td width=350><input type="text" name = "Other_Room" size = 20
onBlur="javascript:SwapOther(this.form);"></td>
   </tr>
   <tr>
      <td align=right width=350>Your chosen room: </td>
      <td width=350><input type="text" name = "Chosen_Room" readonly ></td>
   </tr>

</table>
</form>

</body>
</html>
===============================

Jerry
----- Original Message -----
From: <anne.do@c...>
To: "javascript" <javascript@p...>
Sent: Wednesday, August 07, 2002 6:48 PM
Subject: [javascript] Drop Down Menu with Javascript


> I have a drop down menu with for the field "Location" with 5 selections.
>
> <SELECT NAME="Room">
> <OPTION VALUE="Main">Main Conference Room
> <OPTION VALUE="Alexandria">Alexandria Team Room
> <OPTION VALUE="Arlington">Arlington Team Room
> <OPTION VALUE="Baltimore">Baltimore Team Room
> <OPTION VALUE="Other">Other Room
> </SELECT>
>
>
> The last one says "Other".  If the user chooses other I want this text
> field box to appear so they can enter an alternate value for other.
>
> Enter other Here: <INPUT TYPE="TEXT" NAME="Room">
>
> I then want the value the user entered to then save as the value for Room
> and not the phrase "Other".  How can I accomplish this with javascript?
>
> Thanks,
> Anne Do
> anne.do@c...
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
>


  Return to Index