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>

Open in new window

PegWebAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
_agx_Connect With a Mentor Commented:
> <a href="javascript:submitForm(frm1)">Add Me</a>    
The form name should be a string, so it enclose it quotes

ie    javascript:submitForm(  'frm1' )

0
 
PegWebAuthor Commented:
Thanks. I knew it had to be something simple I was overlooking.
0
All Courses

From novice to tech pro — start learning today.