...

View Full Version : Dynamic Dropdown Menus and Textboxes



dudeman456
06-03-2005, 09:27 PM
I'm trying to have it, so that when a user clicks on an item in the dropdown menu it will show up in a textbox next to it, and they will be able to select a second item from the text box and that will appear as well. They also should be able to type in the box as well.

What I'm currently using is the same as http://www.felgall.com/jstip37.htm

Which uses the code below.


Thanks




START OF CODE

<script language="JavaScript" type="text/JavaScript">
function addOptions(chosen) {
var selbox = document.myform.opttwo;
if (selbox.options[0].value == " ") {
selbox.options.length = 0;
}
var fnd = 0;
for (n=0;n<selbox.length;n++){
if(selbox.options[n].text == chosen){
fnd = 1;
}}
if (!fnd) selbox.options[selbox.options.length] = new Option(chosen, selbox.options.length);
}

function delOptions(chosen) {
var selbox = document.myform.opttwo;
if (selbox.options[0].value != " ") {
nomatch = new Array();
for (n=0;n<selbox.length;n++){
if(selbox.options[n].text != chosen){
nomatch[nomatch.length] = new Array(selbox.options[n].value, selbox.options[n].text);
}}
selbox.options.length = 0;
if (nomatch.length == 0) {
selbox.options[0]= new Option("Select entries from the list at left"," ");
} else {
for (n=0;n<nomatch.length;n++){
selbox.options[n] = new Option(nomatch[n][1], nomatch[n] [0]);
}}}}
</script>


<form name="myform">
<div
align="center">
<select name="optone" size="1">
<option value=" "
selected="selected"> </option>
<option value="First Choice">First
Choice</option>
<option value="Second Choice">Second
Choice</option>
<option value="Third Choice">Third
Choice</option>
</select>
<select name="opttwo" size="1">
<option value=" "
selected="selected">Select entries from the list at
left </option>
</select>
<br />
&nbsp;<br />
<input name="add" value="Add"
onclick="addOptions(document.myform.optone.options[document.myform.optone.selectedIndex].text);"
type="button" /> <input
name="del" value="Remove"
onclick="delOptions(document.myform.opttwo.options[document.myform.opttwo.selectedIndex].text);"
type="button" /></div>
</form>

END OF CODE

Edit to be more specific.

vwphillips
06-03-2005, 09:48 PM
<!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 FillTB(obj,tb){
document.getElementById(tb).value=obj.options[obj.selectedIndex].text;
// or
// document.getElementById(tb).value=obj.options[obj.selectedIndex].value;
}
//-->
</script></head>

<body>
<select name="" size="1" onchange="FillTB(this,'TB1');" >
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
<input id="TB1" size="10">
</body>

</html>



also see

http://www.vicsjavascripts.org.uk/FormCompendium/FormCompendium.htm#f15

dudeman456
06-03-2005, 10:00 PM
This is great, but I need the user to be able put info in the text box as well as be able to select another item that goes into the box.

This script is alot farder than I was thanks.

vwphillips
06-03-2005, 10:23 PM
but I need the user to be able put info in the text box

Dont understand you can still type in the text box

dudeman456
06-03-2005, 11:09 PM
Yes, but as soon as the user attemps to make a second selection, it disappears, let say you want a "TWO" and since "EIGHT" is not on the list, type that in, and I just remembered I need a "FOUR", everything disappears.

vwphillips
06-04-2005, 10:53 AM
Do yo want Eight added to the Select List

or Do you wat a record of every thing that is entered in the text box?

dudeman456
06-06-2005, 03:23 PM
Yes I want a all that is selected.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum