PDA

View Full Version : Dealing With Multiple Select Tags


topher793
08-11-2008, 11:23 PM
I am trying to make an order form using asp/vbscript that will get the values of multiple HTML select menus at one button click, and then pass that all of the information to another asp page which will do the processing and deal with the database stuff. my problem is that i am unable to retrieve each value from the select menus, instead i only get 0 the default value. does anyone know how i can accomplish this? my original idea was to just put all values in an array and pass that to another page which will deal with each item.

i have pasted my code bellow.
THanks!


if not rs.bof or not rs.eof then
do while not rs.eof
thisformlet = ""

dim thepic
thepic =rs("picture")
cstr(thepic)




if cat = rs("type")then
%>
<form name="order1" method="post" action="default5.asp" >
<tr align="center">
<td width="25%" ><a class="thumbnail" href="#thumb"><%=rs("formnum")%><span><img src=<%response.Write(thepic)%> border="0" /></span></a></td>
<td width="25%"><%=rs("Description")%></td>
<td width="25%"><%=rs("Packs Of")%></td>
<td width="25%" valign="middle">
<select name="qty<%response.Write(count)%>">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
</tr>

<%
rs.movenext

else


cat = rs("type")
newcat = 1
if newcat = 1 then%> <!--a new catagory is discovered-->
<tr><td align="left" bgcolor="#808080" colspan="4" height="30px"> &nbsp; <font color="ffffff" style="font-size:12pt"><b>
<%
response.Write(cat) %></b></font></td> </tr> <%
newcat = 0
end if
%>
<tr align="center">
<td width="25%" ><a class="thumbnail" href="#thumb"><%=rs("formnum")%><span><img src=<%response.Write(thepic)%> border="0" /></span></a></td>
<td width="25%"><%=rs("Description")%></td>
<td width="25%"><%=rs("Packs Of")%></td>
<td width="25%" valign="middle">
<select name="qty<%response.Write(count)%>">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
</tr>
<%

rs.movenext
end if

count = count + 1 ' gives all qty boxes unique names
loop

else
response.Write("<tr align=""center""><td colspan=""8"">There are currently no forms available to order.</td></tr>")
end if



rs.close()
set rs = nothing
%>



</td></tr>
<!-- content ends here -->
</td>
</td>
</tr></table>




<br />


<input type="button" name="order1" value="Order!" onClick="">
</form>




<%
dim totalsize
totalsize= count
count = 0

for count= 0 to totalsize
qtyname = "qty" & count
response.Write(qtyname)
request.Form(qtyname)
If qtyname<>"" Then
response.Write("the item is be written")
count
End If
count = count+ 1
next

SSJ
08-12-2008, 11:38 AM
Try to loop through all the form elements dynamically.
You can use the following code for the same:

for each obj in request.form
fieldName = fieldName & "," & obj
fieldvalue = fieldvalue & "," & request(obj)
next

Hope it helps..

Spudhead
08-12-2008, 12:02 PM
Two things.

First, please put code into [ CODE ] brackets when you're posting. It makes it much easier for us to read.

Second, it's not clear what the logic of this page is trying to accomplish but I'd have a good look at the HTML it's outputting. It looks to me like you're only writing the opening <form> tag if the condition of an if..else is met, and you're writing the closing </form> tag if that condition isn't met. So I'd check first of all that you're outputting a correctly formatted, valid HTML form.