8 Replies Latest reply on Feb 8, 2007 7:11 PM by azadisaryev

    javascript form submit

    RyanG24
      Hi i am using javascrpit to submit my form with the code below, but because i have a cfoutput query in the form it is submiting all form elements i need it to submit the current record the submit btn is on ie
      <form>
      <cfoutput query>
      Record1 Submit
      Record2 Submit
      Record3 Submit
      </cfoutput>
      </form>
      so if record 1 submit was click only that record would get submitted to the action page
      full code below
        • 1. Re: javascript form submit
          azadisaryev Level 1
          no, it has nothing to do with <cfoutput>. it will submit all form elements because they are all in one form. it is the FORM that is submitted, not individual elements of a form.

          separate your 3 records into separate forms to submit them individually, or give each submit button a unique name and then in the from processing script check which submit button was clicked and process only corresponding record's value.
          • 2. Re: javascript form submit
            RyanG24 Level 1
            Hi so if i have
            <a href="javascript:not_used()">SUBMIT DISCOUNT</a> and i want to add #GetCust.CustomerID# to this value, so it submits this record, how would i do it?

            i have this javascript code as well
            <script language="javascript">
            <!--
            function not_used() {
            var answer = confirm ("THIS WILL UPDATE CUSTOMERS DISCOUNT & \nSEND THE CUSTOMER AN EMAIL WITH THERE LOGIN DETAILS")
            if (answer)
            window.document.form3.submit();
            }
            //-->
            </script>
            • 3. Re: javascript form submit
              azadisaryev Level 1
              i think in your case it will be easiest to have a separate form for each of your records, ie switch around <form...> and <cfoutput> so that your <form...>...</form> is inside the <cfoutput> tag. also change your submit link to a submit button with an onclick event calling your javascript. that way you will only submit one record and it will be easy for you to process it on the action page.
              • 4. Re: javascript form submit
                RyanG24 Level 1
                ok thanks i have done that but now get a javascript error do i have my onclick right?

                <input type="button" onClick="javascript:not_used()">
                • 5. Re: javascript form submit
                  azadisaryev Level 1
                  remove javascript: from the onClick and put ; after not_used()

                  <input type="button" onClick="not_used();">
                  • 6. Re: javascript form submit
                    azadisaryev Level 1
                    oh, and better change the call and your function to:
                    call:
                    <input type="button" onClick="not_used(this.form);">

                    function:
                    function not_used(objForm) {
                    var answer = confirm ("THIS WILL UPDATE CUSTOMERS DISCOUNT & \nSEND THE CUSTOMER AN EMAIL WITH THERE LOGIN DETAILS");
                    if (answer){
                    objForm.submit();
                    }
                    }
                    • 7. javascript form submit
                      RyanG24 Level 1
                      ok done that but i now get a javascript error, the popup dosent appear?
                      • 8. Re: javascript form submit
                        azadisaryev Level 1
                        hmm...
                        ok, change your code to the following (tested and working):

                        function: (note: this is a new function - replace your old one with this one)
                        function checkAnswer(objForm){
                        if (confirm("THIS WILL UPDATE CUSTOMERS DISCOUNT & \nSEND THE CUSTOMER AN EMAIL WITH THERE LOGIN DETAILS")){
                        return true;
                        } else {
                        return false;
                        }
                        }

                        function call:
                        NOTE: the call is moved to an onSubmit event of the form, so what you need to do is:
                        a) change your <input type="button" onClick="not_used(this.form);"> to
                        <input type="submit" name="submit" value="Update" />

                        b) change your <form... > to
                        <form method="post" action="InsertDiscount.cfm" onSubmit="return checkAnswer(this);">

                        now it will work as you want it to.

                        cheers