1

When I click on SUBMIT it's doing nothing. But I need to send form data to an external link. How can I do this?

   <form role="form" class="registration-form" action="javascript:void(0);">
      <fieldset id="1ststep" class="show">...

       .........Different input fields go here.......

      <div class="text-center btn-box">
         <button type="submit" class="btn Dbtn9" 
            id="btn10thstep">SUBMIT</button>
      </div>
   </form>
7
  • 1
    post your javascript code Commented Nov 20, 2017 at 17:33
  • you need a name in order to send data from your form inputs Commented Nov 20, 2017 at 17:34
  • On submit the action is executed which in your case is javascript:void(0); - you sure that is what you want? Commented Nov 20, 2017 at 17:40
  • Actually, I don't know what is the use of javascript:void(0) in action value and then I replaced it (javascript:void(0)) by the external link but when I click on submit button, it does nothing. Commented Nov 20, 2017 at 18:02
  • 1
    You need to provide a real minimal reproducible example. Include an input. Tell us how you are determining it isn't being sent. You said you replaced action="javascript:void(0);" with the URL you wanted to submit the data to: Show us that. Why do you think you need to use JavaScript? Forms are designed to submit data with just HTML. Why do you think you need to add method="POST"? Commented Nov 20, 2017 at 20:38

2 Answers 2

1

Remember that the inputs needs to have name=""

Sign up to request clarification or add additional context in comments.

Comments

1

After your comment that you do not know about the action="javascript:void(0);" part in your code, here an answer:

If you just need to submit a form, just add the URL as action and the correct method as required by the server. Unless you need to run business logic between the user action and the actual submit to the server, the default browser behavior (without js) works just fine?

Example:

<form role="form" class="registration-form" method="POST" action="/register">

action can be either relative, absolute or a complete URL including protocol and host. However, any GET parameters will be discarded (no matter which method is used to submit). If you need to submit any additional parameters, you have to add them as hidden inputs to the form (or you add them in the AJAX call, if you choose the JS solution).

If you need to run business logic in between the user's submit action and the actual POST or GET to the server, you can either leave the action as is or replace it with #.

<form id="registation-form" role="form" class="registration-form" method="POST" action="#">

in javascript:

let registrationForm = document.getElementById('registration-form');
registrationForm.on('submit', function(event) {
    event.stopPropagation();
    //... your business logic here
    // submit the form, e.g. using jQuery's ajax() function
});

jQuery.ajax(): http://api.jquery.com/jQuery.ajax/

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.