Click to See Complete Forum and Search --> : Submitting Selct List Contents in a form


dru
07-22-2003, 02:39 PM
Hi,
In a form that i created, i allow the user to insert elements into a select list object. these things are lable/value pairs called label and value:
I use the following function to add these values from text boxes to the select list.

function addToList(listField, newText, newValue) {
if ( ( newValue == "" ) || ( newText == "" ) ) {
alert("You cannot add blank values!");
} else {
var len = listField.length++; // Increase the size of list and return the size
listField.options[len].value = newValue;
listField.options[len].text = newText;
listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered)
form1.sublink_name.value = "";
form1.sublink_label.value = "";
} // Ends the check to see if the value entered on the form is empty
}

now i know that in order for this to work i need to select all the values in the select list when submitting it, which i do when submitting, so that the querysting has all the values. however, when i look at the querysting i only see the lables, no values. is there a trick to submitting also the values of the select list to the query string?
any help is appreciated

Khalid Ali
07-22-2003, 02:44 PM
show the code that your are using to append values from list box to query string...

dru
07-22-2003, 03:10 PM
well i thought when submitting the form, the values and fields should automatically be appended to the querystring.
all i had to do was insert a piece of code that selects all the items in the list and then submit (onSubmit).
the code that selects the list items was this:

for (i=0; i<document.form1.sub_links.length; i++) {
document.form1.sub_links.options[i].selected = true;
}

sub_links is the select box. it should store lable and value fields in it.

thanks

Khalid Ali
07-22-2003, 03:13 PM
This is probably true if your list box is set for multiple selection...

dru
07-22-2003, 03:40 PM
It is set at multiple, how do i retrieve those values (text/value) from the query string? the only thing that is visible in the Qstring is sub_links=...the label name....
this variable is the same as the select name.

dru
07-22-2003, 09:07 PM
I should also mention this,
initially the select list is empty.
<select name="sub_links>
</select>
the values are added dynamically using the value and text property of the select box.