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

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

$('#first').click(function() {
    open_new_tab = false;
});

$('form#frm').submit(function(){    
    if (open_new_tab) {
        alert('opening to new tab');
        $(this).attr('target', '_blank');
    } else{
        alert('opening to self_page');
        $(this).attr('target', '_self');
    }
});