Page 1 of 1
Listbox...help??
Posted: Wed May 25, 2005 9:42 pm
by Jeslyn
Hi everyone...
this seems like a very easy question...but is it possible to have a drop down list where besides selecting values from the list, user can also enter other values...which will then be stored in a database?
thanx alot..

Posted: Wed May 25, 2005 10:38 pm
by hongco
i doubt it
Posted: Wed May 25, 2005 10:53 pm
by Burrito
sure, mean a text box where people can enter a "new" value do you? Have that new value added to the select box for future selections you want?
be done using a combination of JS (if want it on the same page load you do), and php this can be.
if interested in some code you are, let me know you should and some code I will post.
Posted: Wed May 25, 2005 11:01 pm
by Jeslyn
actually i think what i mean is a combo box...
something like...i can select from the drop down list as well as enter a new value if i want to...
yupz...i'll appreciate some code...thanx

Posted: Thu May 26, 2005 12:08 am
by hongco
Burrito wrote:sure, mean a text box where people can enter a "new" value do you? Have that new value added to the select box for future selections you want?
be done using a combination of JS (if want it on the same page load you do), and php this can be.
if interested in some code you are, let me know you should and some code I will post.
I am intrested to know. Please post the js Burrito

Thankssss
Posted: Thu May 26, 2005 11:06 am
by Burrito
Code: Select all
<!DOCTYPE HTML PUBLIC "e;-//W3C//DTD HTML 4.01 Transitional//EN"e;>
<html>
<head>
<title>Untitled</title>
<script>
function addNew(what){
var nOption = document.createElement("e;OPTION"e;);
document.MyForm.MySelect.options.add(nOption);
nOption.innerHTML = what;
nOption.Value = what;
}
</script>
</head>
<body>
<form name="e;MyForm"e;>
<select name="e;MySelect"e;>
<option value="e;Burrito"e;>Burrito</option>
</select><br>
<input type="e;text"e; name="e;newOption"e; onBlur="e;addNew(this.value)"e;>
</form>
</body>
</html>
that will add the new option on blur of the text box. If I were the one doing this, I would also add some xmlhttp (yes I know, I'm beating this like a dead horse...but it's sooo good) to update the database so on a page refresh, the new option comes down from the database.
if you need some help with that let me know.
Posted: Thu May 26, 2005 11:24 am
by phpScott
nice work, but it's still not a combo box, which to me would be the holy grail of form elements.
I know it can be done with a judiscious use of javascript and css but I haven't had the time to figure it out yet.
Posted: Thu May 26, 2005 11:26 am
by Burrito
this then maybe
a little ugly but with some work might work out ok...
Posted: Thu May 26, 2005 12:51 pm
by Burrito
ok my interest was piqued so I started working on something:
Code: Select all
<html>
<head>
<title>Untitled</title>
<script>
function addNew(what){
var nOption = document.createElement("e;OPTION"e;);
var tfield = document.MyForm.newOption;
document.MyForm.MySelect.options.add(nOption);
nOption.innerHTML = what;
nOption.Value = what;
tfield.size = (what.length-5);
}
</script>
</head>
<body>
<div style="e;z-index:-10"e;>
<form name="e;MyForm"e;>
<select name="e;MySelect"e;>
<option value="e;"e;></option>
<option value="e;Burrito"e;>Burrito</option>
</select>
</div>
<div style="e;position:absolute;left:8;top:8;z-index:15"e;>
<input type="e;text"e; name="e;newOption"e; onBlur="e;addNew(this.value)"e; size="e;4"e;>
</div>
</form>
</body>
</html>
this only "works" in firefox and it needs a lot of tweaking to make it work better. for example the text field size grows waaay too big on some values entered in..try entering "bling bling" and it grows to about the right size. Then try "123" and it grows way too big. It's a start though and can hopefully get you moving in the right direction if you must have the text field directly on the "select" a true "combo" box.
Posted: Thu May 26, 2005 11:24 pm
by harrisonad
A combobox is just a combination of selectbox and inputbox where users can either select from options or enter other value (ei. not to add it as new option)