user3428959
user3428959

Reputation:

How can i submit form and move to the next page both at a time?

part of my HTML code:

<form method="post" id="form">

<input type="number" min="0" max="20" id="experience" required name="experience"title="experience" class="formfield" />

<input type="image" id="registersubmit4" name="registersubmit4" src="images/arrow-right.png"  title="next"/>

</form>

I want to submit form when user clicks on next and after submitting, then move to the next page.

<input type="image">

works well for submitting but after submitting i want to move to the next page..

I used javascript for onclick() event as follows:

<input type="image" onclick=form.submit(); "location='next.html'">

this does not work. Please help...Thanks in advance.

Upvotes: 0

Views: 14974

Answers (3)

rahul
rahul

Reputation: 1

I used this to solve my problem.

jQuery(window).attr("location", "your page or external link goes here");

Upvotes: 0

Tony Zampogna
Tony Zampogna

Reputation: 2046

Take a look at jQuery.post. You could try doing something like this.

<script>
  // Attach a submit handler to the form
  $( "#form" ).submit(function( event ) {
    // Stop form from submitting normally
    event.preventDefault();

    // Get some values from elements on the page:
    var $form = $( this ),
        exp = $form.find( "input[name='experience']" ).val(),
        url = $form.attr( "action" );

    // Send the data using post
    var posting = $.post({
      url: url,
      data: { experience: exp } );
      success: function( data ) {
        window.location='next.html';
      }
    });
  });
</script>

Upvotes: -2

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114377

This is usually done by specifying an action on the form:

<form method="post" action="newpage.html" id="form">

...but if the page processing your form is different than the page you want to go to, you'd use a server-side redirect. How this works will depend on the server-side language you are using.

Upvotes: 7

Related Questions