Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2004, 12:32 AM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default show new textfield from drop-down list

hi all

i have a form with a drop-down list that allows the user to choose different categories or add a new category, if 'add a new category' is selected, a textfield will show up beside the drop-down list that allows the user to enter the new category

what do i have to do to achieve this???

 
Old March 11th, 2004, 05:08 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You have two choices, either have a textfield always in the page but hidden until the user chooses 'add a new category' or create a new field from scratch using the DOM and insert it into the page. The first choice is probably easier. You may have to make some changes to support older browsers but this should work on IE and modern Mozilla types. In your list box have an onchange that calls showTextbox(this), I'm assuming the add new is the last choice in the listbox:
Code:
function showTextBox(Listbox)
{
  if (Listbox.selectedIndex == (Listbox.options.length - 1))
  /*To check on a specific value have if (Listbox.options[Listbox.selectedIndex].value == "<value here>")*/
  {
    document.getElementById("txtNewCategory").style.display = "";
  }
}
In the form have
Code:
<input type="text" id="txtNewCategory" name="txtNewCategory" style="display:none">
--

Joe
 
Old March 11th, 2004, 09:16 PM
Authorized User
 
Join Date: Jan 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i see, i've managed to get it working

thanks joe






Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down list ashu_gupta75 Excel VBA 1 October 15th, 2007 05:52 PM
show div over top of selects (drop downs) crmpicco Javascript How-To 10 February 14th, 2006 05:48 AM
show/hide text field from select (drop down) Gotaka4 Javascript 6 December 7th, 2005 05:44 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Drop Down List mrideout BOOK: Beginning ASP.NET 1.0 6 March 18th, 2005 03:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.