JSFiddle - React, Tailwind, and code Playground

HTML

<?php 

if(isset($_POST['first'])){
echo "You should still be here with ".$_POST['data'];
}
if(isset($_POST['second'])){
echo "You should be in another tab with ".$_POST['data'];
}
?>
<form id="frm" action="" method="post" target="_blank">
<input type="text" value="data" name="data">
    <input type="submit" name="first" id="first" value="Self"/>
    <input type="submit" name="second" id="second" value="Tab"/>
</form>

JavaScript

$('form#frm').submit(function(){
    var open_new_tab = false;
       
    if($('#second').click){
        open_new_tab = true;
    }

    if ( open_new_tab ) {
        alert('opening to new tab');
        $('form#frm').attr('target', '_blank');

    }
    else{
        alert('opening to self_page');
        $('form#frm').attr('target', '_self');

    }
});