I have a form that looks like this Show
and I would like to stay on the same page, when Submit is clicked, but still have How should that be done? asked Apr 20, 2011 at 16:48
2 99% of the time I would use XMLHttpRequest or fetch for something like this. However, there's an alternative solution which doesn't require javascript... You could include a hidden iframe on your page and set the target attribute of your form to point to that iframe.
There are very few scenarios where I would choose this route. Generally handling it with javascript is better because, with javascript you can...
answered Apr 20, 2011 at 16:52
jessegavinjessegavin 72.1k27 gold badges137 silver badges164 bronze badges 7 The easiest answer: jQuery. Do something like this:
If you want to add content dynamically and still need it to work, and also with more than one form, you can do this:
Riley Lark 20.4k14 gold badges79 silver badges126 bronze badges answered Apr 20, 2011 at 16:52
Herman SchaafHerman Schaaf 44.6k20 gold badges98 silver badges137 bronze badges 25 The HTTP/CGI way to do this would be for your program to return an HTTP status code of 204 (No Content).
answered May 7, 2013 at 12:36
5 When you hit on the submit button, the page is sent to the server. If you want to send it async, you can do it with ajax.
Paritosh 1,0631 gold badge12 silver badges29 bronze badges answered Apr 20, 2011 at 16:51
Eric FrickEric Frick 8351 gold badge7 silver badges17 bronze badges Use XMLHttpRequest
answered Jan 16, 2019 at 20:49
Hasan A YousefHasan A Yousef 20.5k22 gold badges119 silver badges180 bronze badges How do I get javascript to stay on the same page?Bookmark this question. Show activity on this post. onClick=validateForm() it shows alert if it is blank but it goes to next page("action=some.
How do I stay on the same page after clicking?You can use preventDefault() on the click event for a given html object. This will prevent the browser from taking the default action on a specific HTML object.
How do you stay on the same page after submit in HTML?In order to stay on the same page on submit you can leave action empty ( action="" ) into the form tag, or leave it out altogether. For the message, create a variable ( $message = "Success!
How can I submit a form without refreshing the page?Submit a Form Without Page Refresh Using jQuery. Build the HTML Form. Let's take a look at our HTML markup. ... . Begin Adding jQuery. The next step in the process is to add some jQuery code. ... . Write Some Form Validation. ... . Process Form Submission With the jQuery AJAX Function.. |