Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Dropdown Menus and Textboxes 1

Status
Not open for further replies.
Jun 3, 2005
25
US
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.

What I'm currently using is the same as
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
 
I must have entered it in a wrong way, because your last code, the one you did not get the message one, works with no errors.

So, I'll just compare the coding, but Thanks alot, this has been such a great help.
 
What would make Firefox say

Error: document.getElementById(x2) has no properties ?

So far the code looks the same.
 
you're passing an incorrect name of a textbox...it's saying that the value stored in 'x2' does not exist, or it has no properties...look for the naming of input text boxes...it can't find any element named (value of x2).

- g
 
it points to line 1240 being the problem, which is

if (sOption == '') {document.getElementById(x2).value=x+"\n";}

does that still mean its a textbox name issue?
 
Also the name that I'm using for the box has an _(underscore) in the middle, can the script process _s?

text_box
 
Sorry to keep doing this, but yes, I changed the name from a name with an underscore to a name without an underscore and it seems to process it.
 
I need help with this topic. I change the size to 6 in order to allow user select multiple items, it works then, but how can I pass the selected items (in the second list) to next page, I try it, it always and only pass one item as the form value, for example, if I select 3 items from the first list and put them into the second list, then I want to pass these 3 items to a next page, when I click on the submit, it only pass the first one of those 3 items to the next page, please advise how to do it? and pass the correct values through the form action?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top