Solved

Combo box in HTML form?

Posted on 2004-04-29
2
256,523 Views
Last Modified: 2011-08-18
I'm making a form with HTML--I'm still learning, but I haven't found a way to have a scroll menu that lets you choose OR enter a new value that then gets added to list. I've done something like this with databases (I think it's called a combo box), I'm just not sure whether it's do-able with HTML.

Example: I want a user to enter a species name. They can choose from maple, birch, or hickory. But this year, there's a new species to consider: tulip. How can I make it so that the visitor can enter this value that is not already on the list? And is it possible to have this new value automatically appended to the list?

Here's what I have so far:  


    <select name="menu" size="3" multiple>

        <option value="1">maple</option>

        <option value="2">hickory</option>

        <option value="3">birch</option>

    </select>

</form>

Thanks in advance for your help.

-Krystle
0
Comment
Question by:KrystleBlair
2 Comments
 
LVL 31

Accepted Solution

by:
seanpowell earned 100 total points
ID: 10954384
Have a read through this:
http://www.cs.tut.fi/~jkorpela/forms/combo.html
Let us know if you need more info...

Thanks,
Sean

0
 
LVL 1

Expert Comment

by:garethdart24
ID: 10966373
You could use a javascript solution:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<style>
</style>
<script language = "javascript">
<!--
var firstBit1 = "<select name='menu' id = 'menu' size='";
var firstBit2 = "' multiple='multiple'>";
var orig_conts = "<option selectec value='1'>maple<option value='2'>hickory<option value='3'>birch</option>";
var lastBit = "</select>";
var size = 3;
var x = 3;

function initRefresh() {

//replace size with x to make the dropdown list increase in vertical size with each selection
document.getElementById('div').innerHTML = firstBit1 + size + firstBit2 + orig_conts + lastBit;

}

function addItem() {

x++;
orig_conts =  "<option value = '" + x + "'>" + document.form.add.value + "</option>" + orig_conts;
initRefresh();
document.form.add.value = "";
document.form.menu.selectedIndex = 0;

}

//-->
</script>
</head>
<body onload = "initRefresh()">
<form name = "form" id = "form">
<div name = "div" id = "div"></div>
<input type = "text" name = "add" id = "add"><br>
<input type = "button" value = "Click" onclick = "addItem()">

</form>
</body>
</html>

Hope that's helpful,

G
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now