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.
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.
Share Improve this question asked Mar 17, 2014 at 18:04 user3428959user3428959 3- Maybe give the redirecting task to the file you are submitting to. – Hanlet Escaño Commented Mar 17, 2014 at 18:05
- See Diodeus's answer. So it is <form method="post" action="next.html" id="form">.......</form> – lshettyl Commented Mar 17, 2014 at 18:27
- And please have quotes for the attribute values, such as onclick="form.submit();" – lshettyl Commented Mar 17, 2014 at 18:29
3 Answers
Reset to default 7This 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.
I used this to solve my problem.
jQuery(window).attr("location", "your page or external link goes here");
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>