Reg Exp
Web Design
Notes Client
Multi-Value Fields
Let's say you have a situation where you want to have a user input multiple values in a certain order but you don't know at design time how many fields will be there, but you do know you want to store them all in a single multi-value field. This can be done pretty easily in a browser.

For example, let's say you want your user to be able to choose what states they sell their product to. Then, for every state you're going to need a state sales tax percentage. On one form you can give a check box field with all the possible state names, but when you're filling out the sales tax percentages, you only want to display just enough fields (one for each state name) and store them in a multi-valued field.

On a form or $$NavigatorTemplate you should build your HTML form tag to show to the user. Here's an example using straight HTML:

<form name=thisForm method=post action=./SalesTax?CreateDocument>
<input type=hidden name=multi> <!-- this field holds the multiple values -->
<input name=single>
<!-- these fields hold the values the user will input -->
<input name=single>

<input name=single>

<input name=single>

<input type=button value="Submit" onClick="submitForm()">
<script language="JavaScript"><!--
// build the submitForm function to populate the hidden multi field before submitting the form
function submitForm() {
   var longString = ""; // Initialize a variable to hold the value for "multi"
   for (var i = 0; i < document.thisForm.elements.length; i++) {
      if (document.thisForm.elements[i].name == "single") { // if it's one of the user input fields
         // append a delimiter if there's 1 or more in the list
         if (longString.length != 0) { longString += ";" }
         longString += document.thisForm.elements[i].value; // append the value
      } // Ends the check to see if it's one of our fields or not
   } // Move on to the next form field
   document.thisForm.multi.value = longString; // put the value into the hidden field
   document.thisForm.submit(); // send the form to the server
} // Ends the "submitForm" function
// -->

Then, on the "SalesTax" form (the one refered to in the "action" parameter on the "form" tag), all you need are two fields -- one called "Single" and a multi-value field called "Multi". You never know what value "Single" will have (it usually will have the first field value, but not always, and it depends if you defined "Single" to allow multiple values or not) but you only care about the field "Multi", anyway. You could put in validation in the JavaScript to make sure there's a value in each of the input fields if you want.