Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    Argentina
    Posts
    58

    Unanswered: loop through dynamic form fields

    Hi! I have a dynamic form (I create a dynamic number of rows) and then I send it to another page to proccess it. I'm having problem to retrieve the fields...or at least in the correct order

    Form:
    Code:
    <form name=gen action='generate.asp' method='post'>
    <table>
    	<tr><td>Field</td><td>Type</td><td>Size</td></tr>
    	<%
    		lc_rows = 0
    		do while  lc_rows < limit
    			lc_rows = lc_rows + 1
    			response.Write("<tr>")
    				response.Write("<td>")
    					response.Write("<input name='val1__"&cint(lc_rows)&" type='text' value='"&some_value&"' readonly>")
    				response.Write("</td>")	
    				response.Write("<td>")
    					response.Write("<input name='val2__"&cint(lc_rows)&" type='text' value='"&other_value&"' readonly>")
    				response.Write("</td>")					
    		LOOP	
    %>
    <tr><td colspan=2 align='center'>
    <input type='submit' name='Submit' value='Go!'>
    </td></tr>
    </table></form>
    Procesing side:
    Code:
    lc_temp = 1
    for each variable_name in request.form
    	if ((lc_temp mod 2) = 0) then
    		response.Write("<br>")
    	end if	
    	variable_value=request.form(variable_name)
    	
    	if instr(1,variable_name,"val1__") > 0 then 
    		response.write "("& variable_value &") "	
    	else
    		response.write variable_value &" "	
    	end if	
    		
    	lc_temp = lc_temp + 1 
    next
    It's printing... but in a strange order.... is there an order or something??

    Thanks!!!

  2. #2
    Join Date
    Feb 2004
    Location
    Argentina
    Posts
    58

    fixed!!

    To maintain the order use

    Code:
    For ix = 1 to Request.Form.Count
        fieldName = Request.Form.Key(ix)
        fieldValue = Request.Form.Item(ix)
    
    
    next
    source: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=64

    Note: I searched before but didn't find anything....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •