Tabbed Content / Posts /

How to open POST page in the same tab?

If I include form inside a tab, and click submit button, POST page opens as a new page. But I want to open it inside the same tab and not as a new page. How can I do that?
Apurvd  9 years ago   viewed: 3871    

4 Answers

You may need to read Other Ways to Select a Tab on the page But it is not free to use.
Julia   9 years ago
let me give more clarification.. I want to open a link in the same tab currently the link get opened in as new page within browser.. i want to retain original page and open the link just inside tab..I want same behavior when the form inside tab is POSTed...hope you got it now
Apurvd   9 years ago
It sounds like you want to populate the current tab content with the content retrieved from another page. That is Ajax. You can read the Ajax section of Menucool's jQuery Tabs.
Milo   9 years ago

To open the POST response page inside the same tab instead of opening it as a new page, you can use JavaScript to handle the form submission and prevent the default behavior of the form.

Here's an example of how you can achieve this that I refer in territorial io

Add an id attribute to your form element, for example:



<form id="myForm" action="submit.php" method="POST">

  <!-- form controls here -->

  <button type="submit">Submit</button>


Add a JavaScript function that handles the form submission and prevents the default behavior of the form:



function submitForm() {

  var form = document.getElementById("myForm");

  form.addEventListener("submit", function(event) {

    event.preventDefault(); // prevent default form submission

    var xhr = new XMLHttpRequest();"POST", form.action); // set up the POST request

    xhr.onload = function() {

      if (xhr.status === 200) { // check if the response is successful

        // update the content of the current tab with the response

        document.getElementById("myTab").innerHTML = xhr.responseText;



    xhr.send(new FormData(form)); // send the form data





Add an id attribute to the tab that you want to update with the POST response, for example:


<div class="tab" id="myTab">

  <!-- tab content here -->


With these changes, when the user clicks the Submit button, the form will be submitted using the XMLHttpRequest object, which will send the POST request in the background without reloading the page. The response will then be processed in the JavaScript function, and the content of the tab will be updated with the response.

  2 months ago


Your name*
(Optional. Used to modify this post afterwords)
+ =  

Ask your Own Question

  • If your question is related to the topic of this post, you can post your question to this page by clicking the "Post a reply" button at left;

  • When you want to start a new page for your question: