PegWeb
asked on
ColdFusion.Ajax.submitForm and multiple forms
How can I use this code when I have multiple forms on a page? In the first code block you see the code that works fine. It posts to the form-action.cfm file and sends back what I need. However if I have say 25 forms on a page for a shopping cart system how can I have it call a specific form? The second block of code is what I would think would work but it doesn't. All I am trying to do is pass the form name to the function as a variable but it is not working. Any ideas?
<cfajaximport>
<script>
function submitForm() {
ColdFusion.Ajax.submitForm('myform', 'form-action.cfm', callback, errorHandler);
}
function callback(text)
{
alert("Callback: " + text);
}
function errorHandler(code, msg)
{
alert("Error!!! " + code + ": " + msg);
}
</script>
<cfform method="get" name="myform" id="myform">
<cfinput name="tinput1"><br />
<cfinput name="tinput2"> <br />
<a href="javascript:submitForm()">Add Me</a>
</cfform>
SECOND SET OF CODE
<cfajaximport>
<script>
function submitForm(frmName) {
ColdFusion.Ajax.submitForm(frmName, '~form-action.cfm', callback, errorHandler);
}
function callback(text)
{
alert("Callback: " + text);
}
function errorHandler(code, msg)
{
alert("Error!!! " + code + ": " + msg);
}
</script>
<cfform method="get" name="frm1" id="frm1">
<cfinput name="tinput1"><br />
<cfinput name="tinput2"> <br />
<a href="javascript:submitForm(frm1)">Add Me</a>
</cfform>
<cfform method="get" name="frm2" id="frm2">
<cfinput name="tinput1"><br />
<cfinput name="tinput2"> <br />
<a href="javascript:submitForm(frm2)">Add Me</a>
</cfform>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER