Solved

Combo box in HTML form?

Posted on 2004-04-29
2
256,568 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open dialog with server side controls in it 3 46
html border input line 7 26
JavaScript Loan Calculator Error 3 35
Text color and background in a text box. 2 25
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

733 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