PDA

View Full Version : Requesting a textbox with a variable name?


Aiii
10-28-2005, 11:06 AM
I'm a bit of a novice on asp and i'm having some trouble with the request.form command. I have to update a buckload of records at the same time. In the main page I have the following code:

<%
Dim MaatVRRS, MaatVRSQL
Set MaatVRRS = Server.CreateObject("ADODB.Recordset")

MaatVRSQL = "Select * From prijzen "_
&"WHERE productnr = 1 order by breedte, hoogte asc"

Call MaatVRRS.Open (MaatVRSQL, strCon)

Call MaatVRRS.Movefirst()
While not MaatVRRS.EOF
%>

<tr>
<td><font face="verdana" size="2" color="#000000"><center><b><%=MaatVRRS("breedte")%></b></center></font></td>
<td><font face="verdana" size="2" color="#000000"><center><b><%=MaatVRRS("hoogte")%></b></center></font</td>
<td><font face="verdana" size="2" color="#000000"><center><b><input type="text" value="<%=MaatVRRS("prijs")%>" name="<%=MaatVRRS("id")%>"></b></center></font></td>
</tr>

<% Call MaatVRRS.Movenext()
Wend %>

As you can see the name of the textbox is variable from the databases "id" column.

Now when I try to process (update) the information from the textboxes (once again using a while loop to go through the records) in my database I cannot seem to get the input text using the Request.Form command. In the loop in that page I'm trying to update the field prijs by requesting like this:

prijsid = MaatVRRS("id")
prijs = Request.Form("'"&prijsid&"'")

Problem is, this returns an empty field and not the value input in the textbox with that variable id.

Is it at all possible to use variable names from textboxes or is this a lost cause? Any help would be greatly apreciated.

TIA.

BaldEagle
10-28-2005, 08:26 PM
This should work if you remove the delimiters:

prijsid = MaatVRRS("id")
prijs = Request.Form(prijsid)


BaldEagle

Aiii
10-31-2005, 07:59 AM
unfortunatly doesn't work, returns:

Request object error 'ASP 0105 : 80004005'

Index out of range

/admin_maten_exec.asp, line 35

An array index is out of range.

Roelf
10-31-2005, 09:29 AM
can you check the form (where the fields are created dynamically) to see if the id's (content of name-attribute in the input field) are the same as the ones you try to access in the processing page (response.write the prijsid values in this page)

Do they match??

altijd grappig om nederlandstalige objectnamen te zien op deze site

Aiii
10-31-2005, 01:20 PM
yup, the id's do show up properly in the form, in fact everything except prijsid shows up as it should.

Roelf
10-31-2005, 02:07 PM
so if i am right:

the generated form (with the dynamically created fields) has the proper name-attributes, and the page which processes the form tries to access the Request.Form(prijsid) field and then the error occurs. You have tried to response.write this prijsid in the processing page and there is the correct prijsid returned, but when trying to access the Request.Form collection, the error occurs.

Is the </form> tag before the creation of the input fields?? so the fields are no part of the Request.Form collection????

Aiii
10-31-2005, 02:19 PM
yes it is.

I have since implemented a different way of modifying prices with percentages to modify said prices, works faster at any rate.

ta for the help.