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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PegWebAuthor Commented:
Thanks. I knew it had to be something simple I was overlooking.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.