1

I got well working form. Inside I have button that submit my form with onclick="form_submit().

THIS CODE SAMPLE WORKS FINE BUT WITHOUT SENDING CONTROL-SUM.

function form_submit(){
    $("#add_form").submit();
}

Now I need to send some control-sum with POST on submit form. This control sum is inside other form input so it won't send with this one.

It is necessary to use non AJAX solution. So I tried this way but without success.

function form_submit(){
   $("#add_form").submit(function() {
       $.post('url.php', $("#control-sum").serialize());
   })
}

Could you tell me please, what syntax or method should I use to find the solution?

6
  • Has the submit button a type="submit"? or is a type="button"? Commented Oct 26, 2018 at 16:56
  • Check if button type="submit" and preventDefault the inherit event of the form. submit(function(e){ e.preventDefault(); }); Commented Oct 26, 2018 at 16:59
  • 1
    You could always copy the control-sum from the other form, into your form as a hidden input, before you submit it Commented Oct 26, 2018 at 16:59
  • Submit button is like <button type="button" onclick="form_submit()"> Nice idea to copy input#control-sum with js. Commented Oct 26, 2018 at 17:19
  • have you tried using action tag in form Commented Oct 26, 2018 at 17:24

1 Answer 1

1

Now it works fine and its solution that i need :) Thanks for your help !

function form_submit(){
    var csum_val = $("#control-sum").val();
    var csum_name = $("#control-sum").attr('name');
    $(".jq__add_control_sum").append('<input type="hidden" name="' + csum_name + '" value="' + csum_val + '"/>');
    $("#add_form").submit();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.