Skip to main content
March 27, 2008
Question

onclick form submit from link

  • March 27, 2008
  • 6 replies
  • 12501 views
Guys,

I am calling onclick="document.form.submit();" in a hyper clink.

On click, it goes to a fuseaction where act_load_structure.cfm loads the structure with form variable.

But the form fields are not avaibale in act_load_structure.cfm . It says form fields are not defined. Do you know why.

I appreciate your help in advance.
    This topic has been closed for replies.

    6 replies

    Participating Frequently
    March 27, 2008
    In short:

    <a href="javascript:document.form.submit();">Submit</a>

    :)
    Participating Frequently
    March 27, 2008
    If I understand correct, you are trying to submit a form with a text based link.

    Here is a simplified version:

    <cfif StructKeyExists(form,"tablename")>
    <cfdump var="#form#">
    </cfif>

    <cfform name="form" id="form" action="#cgi.script_name#" method="post">
    <input type="text" name="log" value="mylog" />
    <br />
    <input type="text" name="AcctId" value="123" />
    <br />
    <input type="text" name="tablename" value="test" />
    <br />
    <a href="javascript:document.form.submit();" onClick="">Submit</a>
    </cfform>

    Save as a single file and test it.

    March 27, 2008
    Still does not work. Here is the dsp page

    <cfoutput>
    <cfform name="form" id="form" action="index.cfm" method="post">
    <table>
    <tr>
    <td>
    <input type="text" name="log" value="#attributes.log#" />
    <input type="text" name="AcctId" value="#attributes.AcctId#" />
    <input type="text" name="tablename" value="test" />
    </td>
    </tr>
    </table>
    <table width="100%">
    <tr>
    <td align="left">
    <a href="index.cfm?fuseaction=#XFA.test#&log=#attributes.lo g#&AcctId=#attributes.AcctId#&rn=#attributes.rn#" onclick="document.form.submit();">test</a>
    </td>
    </tr>
    </table>
    </div>
    </cfform>
    </cfoutput>


    Here is the destination page

    <cfoutput> tablename = #form.tablename#</cfoutput>
    <cfabort>

    or

    <cfoutput> tablename = #tablename#</cfoutput>
    <cfabort>


    I appreaciate your help
    Participating Frequently
    March 27, 2008
    The problem is not related with Fusebox etc. This is just a general problem for the form processing. I assume that your code tries GET instead of POST etc.

    I would suggest to create a basic form with same method and share with us just to able to try also in our side.

    Participating Frequently
    March 27, 2008
    Have you tried "this.form.submit()" ? :)


    March 27, 2008
    I tried
    this.form.submit()
    document.form.submit()
    document.form[0].submit()
    document.window.submit()
    window.submit() etc.

    still by the form variable is not avaialble in my fuse action. My problem is the it has to be a link.
    The form i am talking about is like a spread sheet fuctionality with paging. On paging i would like to save the data to the database. All the form variables are dynamic and database driven.
    Astonished_protector15C3
    Participating Frequently
    March 27, 2008
    Hi
    My suggestion is to call a function in the onClick event

    Please try the following line of code

    For eg:
    <form name="form1" method="post" action="act_load_structure.cfm">
    <input type="text" name="name">
    .....
    </form>

    <a href="##" onClick="fn_submit();" >Submit</a>

    <script>
    function fn_submit()
    {
    document.form1.submit();
    }
    </script>

    March 27, 2008
    Thanks.

    onclick="document.form.submit() or submitting in another function works and form variables are available inside the java script. But the form variables are not avaiable in the fuseaction. Any thoughts.