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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing dynamic <option> values 2

Status
Not open for further replies.

flnMichael

Programmer
Nov 13, 2003
96
US
Here's my issue: I have a page that loads up with a variable number of <select multiple> tags. Each select is a different database call to load up into the select. My issue is I need the selected values to go to the next page. The problem is I don't know the names of the options until I load the page and passing them to the validate has become a task for me. How do I get the values when I validate? The way I see it is I need something like this:
document.form.select.option.selected
right?
The names of the options are a combination of database name and unique identifier I need in the next page.

Here's my code
Code:
While Not osRecordSet.EOF 'database list
Response.Write("<select name=partnums_" & counter & " multiple size=6 width=25>")

While Not SteposRecordSet.EOF 'individual database connection
Response.Write("<option value='")
Response.Write(osRecordSet.Fields("database_name") & "_" & SteposRecordset("testdescid"))
SteposRecordSet.MoveNext
wend
SteposRecordSet.Close
osRecordSet.MoveNext

Wend

<td align=center><input type=button name=Submit value=Sumbit onclick='checkvalues(this.form, <%=testdesccount%>);'>

function checkvalues(form, counter)
{
   var temp;
   var i = 0;

   while (i <= 2)
    {
      if (form["partnums_"+i].OPTION.selected)
       {
         array[i] = OPTION.value;
       }
      i = i + 1;
    }

  form.redo_list.value = 1;
  form.submit();
}

the 'OPTION' areas in the function are where I get a little confused as to what I need to get the names of the option tag from the html area. Can somebody help me? I know it may sound a little confusing, but I've had success here with more confusing questions than this so I thought I'd try.

Thanks
Mike
 
I could be wrong, but I think you will run into issues if you try to access something from the forms array using a string values. The forms array is (I believe) strictly an array of all the forms on the page.
A better bet would be to use document.getElementByName() this will return an array of all the elements with a specific name. In your case I would think there would never be more than one element, since your naming each select with a counter.

Now, if your just using that function to somehow grab the selected values for the select boxes, you don't need it.

Option #1
On your next page you could loop through all of the posted form fields and grab only the ones that start with partnumber_
Code:
Dim fldName
For Each fldName in Request.Form
   If InStr(fldName,"partnums_") > 0 Then
      Response.Write fldName & " = " & Request.Form(fldName) & "<br>"
   End If
Next

Option #2
You could also add a hidden field to the end of your first page form that holds the counter you used to name your select boxes. This way you will know the number range for the select boxes and can build names to pull from the Request collection:
Code:
Dim i
For i = 0 to Request.Form("hiddenFieldCounter")
   Response.Write "partnum_" & i & " = " & Request.Form("partnum_" & i) & "<br>"
Next

barcode_1.gif
 
I knew I would get the answers I was looking for. This is EXACTLY what I was looking for. Thanks Tarwn, you get a star for this!!!
 
flnMichael: Not a problem, glad to be of assistance! :)




barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top