Date:  07/18/2008 10:51:43 PM Msg ID:  003771
From:  FoxWeb Support Thread:  003759
Subject:  Re: SELECT / OPTION for a table based form
Your code implements exactly what I had in mind.  This approach eliminates the possibility of problems for any browsers (or server-side frameworks, like FoxWeb for that matter) not returning the form field submissions in the order they exist in the HTML form.
 
I noticed that in a previous example you did not have the text field, but rather had a hidden field, whose sole purpose was to help you identify which table row the corresponding SELECT field referred to.  With this code you no longer need this, so it's possible that the text field is superfluous.
FoxWeb Support Team
support@foxweb.com email
Sent by Jeff Grippe on 07/18/2008 12:46:28 PM:
Here is what I did that seems to give me what I need and solves the problem that you mentioned. Please correct me if I'm wrong.

My form code is:
<TABLE>
  <%select &TheTable%>
  <%scan%>
   <TR>
     <select name="A<%=approvalcd%>">
      <option value="NOTHING">-----------------</option>
      <option value="CLIRISK">Net 30 Client Risk</option>
      <option value="GETCC">Get Credit Card</option>
      <option value="COD">Arrange COD</option>
      <option value="CALLSHOW">Call Showroom</option>
      <option value="CALLME">Call Our Office</option>
     </select>
    <TD align="right"><input type="text" name="N<%=approvalcd%>"></TD>
   </TR>
  <%endscan%>
</TABLE>

and my followup code is:
dime aStuff[1,1]
nTotFields = Request.FormArray(@aStuff)
<HTML>
 <%=nTotFields%>
 <table border>
 <%For i = 1 to ALEN(aStuff,1)%>
  <tr>
  <%for j = 1 to ALEN(aStuff,2)%>
   <td><%=aStuff(i,j)%></td>
  <%next j%>
  </tr>
 <%next i%>
 </table>
 <a href="contact.FWX">Click Here to Return to the Main Menu</a>
</HTML>

This test code showed by that I got an array of form variable names and values. The variable names were alway A or N followed by my key field.

I imagine that it would be better to use something longer than a single character but at least I've proved the concept.

Thanks.

Sent by Jeff Grippe on 07/18/2008 11:44:04 AM:
Hi,
Thanks for the help.

I'm not sure I understand what you are saying (actually I'm sure I don't understand)

Let's say I have one select field and one text field for each record.

You are recommending something like:
<TD><SELECT NAME="sel1_<%=approvalcd%>">
      <option value="NOTHING">-----------------</option>
      <option value="CLIRISK">Net 30 Client Risk</option>
      <option value="GETCC">Get Credit Card</option>
      <option value="COD">Arrange COD</option>
      <option value="CALLSHOW">Call Showroom</option>
      <option value="CALLME">Call Our Office</option>
</SELECT></TD>
<TD><INPUT TYPE="TEXT" NAME="txt1_<%=approvalcd%>">

What does the code that executes after the submit button is pressed look like? With each <SELECT> having a unique name, what do I use to get them into an array?

Would the following work? Or would I need to use the loop that specified earlier?
dime aActionArray[1,1]
nTotSelFields = Request.FormArray(@aActionArray, "sel1_")
nTotTxtFields = Request.FormArray(@aActionArray, "txt1_"

You are also saying that there is no guarantee that the browser will give me matching text and select records as I've outlined in my code.

It hasn't been in production long and my tests using IE (7) worked fine but I'd rather do something that is bullet proof.

Thanks for all the help.

Jeff
Sent by FoxWeb Support on 07/12/2008 10:48:17 AM:
This solution will assumes that the fields will be sent from the browser to the server in the order they appear in the form.  Even though this may be the case with the browsers you are working with, there's no guarantee that this will always be the case.  A safer approach would be to use approvalcd as the name of the SELECT field. If you have move user-editable fields, then you can use different suffixes to each field name (e.g. "<%=approvalcd%>_action" for the action field).
FoxWeb Support Team
support@foxweb.com email
Sent by Jeff Grippe on 07/11/2008 07:03:18 AM:
Hi,

Actually your earlier advice was spot on. I did the following:

    <TD align="center">
     <select name="Action">
      <option value="NOTHING">-----------------</option>
      <option value="CLIRISK">Net 30 Client Risk</option>
      <option value="GETCC">Get Credit Card</option>
      <option value="COD">Arrange COD</option>
      <option value="CALLSHOW">Call Showroom</option>
      <option value="CALLME">Call Our Office</option>
     </select>
     <input type="hidden" name="approvalcd" value="<%=approvalcd%>"></TD>

The field approvalcd is the field that I need to reference the record in the table. The field Action is the new data being supplied by the user.

In the script that is called when the submit button is pressed, I did:

dime aActionArray[1,1]
dime aApprovalArray[1,1]
nTotFields = Request.FormArray(@aActionArray, "Action")
nTotFields2= Request.FormArray(@aApprovalArray, "approvalcd")

I got two arrays that are in sync. I can look at any value in aActionArray and find the corresponding record in aApprovalArray in order to find the database record to update.

I've got it working perfectly.

Thanks.
Sent by FoxWeb Support on 07/09/2008 01:17:37 PM:
I misunderstood your original question.  Instead of giving each select field the same, I recommend that you give it a name that identifies the current record.  If the form contains more than just the select fields in question, then you should probably add something to the name to make it identifiable.  In the example below I'm prepending each select field name with "sel_".  Do you really need the text field?  If you don't expect users to enter any text, just remove it:
<%SCAN%>

<TR>
<TD>
<SELECT NAME="sel_<%=table.key%>">
<OPTION VALUE="FIRST">FIRST OPTION</OPTION>
<OPTION VALUE="SECOND">SECOND OPTION</OPTION>
</OPTION>
</TD>
</TR>
<TR>
<TD><INPUT TYPE="TEXT" NAME="txt_<%=table.key%>" VALUE="_your_default_value_">
</TD>
</TR>
<%ENDSCAN%>
To read user input you will need to traverse all fields with a FOR NEXT loop as described in my previous post.
FoxWeb Support Team
support@foxweb.com email
Sent by Jeff Grippe on 07/09/2008 08:35:46 AM:
So the coding of the form itself is correct as I presented it?

I would use the same name for all select/option groups and then use the methods that you specified to retrieive the data?

If I am going to get back an array of data for the select/option groups then I am also going to need a parallel array so that I can know what each array element relates to in order to update the database. So does the following make sense?

<%SCAN%>

<TR>
<TD>
<SELECT NAME="ACTION">
<OPTION VALUE="FIRST">FIRST OPTION</OPTION>
<OPTION VALUE="SECOND">SECOND OPTION</OPTION>
</OPTION>
</TD>
</TR>

<TR>
<TD><INPUT TYPE="TEXT" NAME="KEY" VALUE="<%=table.key%>">
</TD>
</TR>
<%ENDSCAN%>

This is the same sample code as below but now I've also included something which will give me the database keys that go with the selected options.

Now I could use Request.FormArray for ACTION and for KEY to get two arrays which should be in sync and can be used to point back to the database. Please tell me if this makes sense or if I'm not understanding you correctly.

Thanks for the help.

Jeff

Sent by FoxWeb Support on 07/08/2008 12:40:45 PM:
You will have to use a Request.FormCount("ACTION") to find how many options were selected.  Once you know, you can use Request.Form("ACTION", n) to retrieve each value, where n is a number from 0 to the total number of selected options.  Alternatively, you can use the Request.FormArray method to retrieve an array of all options.  The documentation contains more details on the various methods of the Request object.  Here's some sample code:

TotalSelections = Request.FormCOunt("ACTION")

FOR i = 1 TO TotalSelections

    Response.Write(Request.Form("ACTION", i))

NEXT

 
FoxWeb Support Team
support@foxweb.com email
Sent by Jeff Grippe on 07/03/2008 12:21:54 PM:
Hi, thanks for the help

Suppose I have an HTML table that is on a form and populated by a cursor...

Suppose I want to use a SELECT / OPTION tag to allow the user to update information in multiple records...

How do you deal with the "NAME" property?

If I were to code

<%SCAN%>
<TR>
<TD>
<SELECT NAME="ACTION">
<OPTION VALUE="FIRST">FIRST OPTION</OPTION>
<OPTION VALUE="SECOND">SECOND OPTION</OPTION>
</OPTION>
</TD>
</TR>
<%ENDSCAN%>

Then every select option group would update the same form variable.

Is there a good way to do this?

Thanks,
Jeff