- when user clicks on the submit button, setAction() function is called (JavaScript, client side); function will check the newOption form field and if it's not blank will assign value "addOption" to the form "a(ction)" field;
the form is submitted; on the server, cf is checking if the form.a field is defined at all; if yes, it means that the request is comming from the page with the form on it; next, cf will check if the form field "a" has the value "addOption"; if yes, the only action is to add new record and execute new query; this is enclosed within the cftransaction tags so the second query will wait for the first to be executed in full; after that, the page is sent to the client with new query so the option box will be populated with new data; all other form fields remain same;
however, if the form.a field has the value "submitFrm", the form is complete and you can execute whatever code there and send user to another location;
<cfparam name="field_1" default="">
<cfparam name="field_2" default="">
.
.
.
<cfparam name="field_45" default="">
<cfquery name="customers" datasource="dbn">
SELECT firstName FROM Customers;
</cfquery>
<cfif IsDefined("form.a"

>
<cfif form.a EQ "addOption">
<cftransaction>
<cfquery name="customers" datasource="dbn">
INSERT INTO Customers (firstName)
VALUES ('#form.firstName#');
</cfquery>
<cfquery name="customers" datasource="dbn">
SELECT firstName FROM Customers;
</cfquery>
</cftransaction>
<cfelseif form.a EQ "submitFrm">
<!--- code to process the form in full... --->
</cfif>
</cfif>
<script>
function setAction() {
var frm = window.document.mainFrm;
if (frm.newOption.value != '') {
frm.a.value = 'addOption';
}else{
frm.a.value = 'submitFrm';
}
}
</script>
<form action="<cfoutput>#cgi.Script_Name#?#client.URLToken#</cfoutput>" method="post" name="mainFrm">
<input name="a" type="hidden" value="">
<input name="field_1" type="hidden" value="<cfoutput>#form.field_1#</cfoutput>">
<input name="field_2" type="hidden" value="<cfoutput>#form.field_2#</cfoutput>">
.
.
.
<input name="field_45" type="hidden" value="<cfoutput>#form.field_45#</cfoutput>">
<select name="fourtySixthField">
<cfloop query="customers">
<option><cfoutput>#firstName#</cfoutput></option>
</cfloop>
</select>
<input name="newOption" type="text">
<input name="submit" type="submit" value="Submit" onclick="JavaScript:setAction();" class="submitButton" id="submitButton">
</form> Sylvano
dsylvano@hotmail.com