0

I am using this code:

 var frm = $('#myform');
    frm.submit(function (ev) {

        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
                alert('ok');

            }
        });

        ev.preventDefault();
    });

I Tried:

frm.submit(function (ev) {

   $("#myform").attr('action', 'myurl');

    .....

But that didn't work.

Is there a way to set the form action url after "frm.submit(function (ev) {" ?

6
  • Just concatenate? This is a simple question google would have solved easily. Commented Aug 25, 2014 at 18:24
  • I tried adding "$("#myform").attr('action', 'theUrl');" after frm.submit(function (ev) { but it didn't work which is why I'm asking Commented Aug 25, 2014 at 18:26
  • use prop not attr Commented Aug 25, 2014 at 18:27
  • Tried prop but still no luck Commented Aug 25, 2014 at 18:30
  • then something else is going on. are you debugging the form action as you manipulate it? there's so much unsaid details you havent listed Commented Aug 25, 2014 at 18:31

1 Answer 1

1

Your code should work fine but you have to enclose it in DOM ready or placed it at the end of your page.

$(document).ready(function() {
    //your code
});
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.