1

Hi I have this javascript code that works fine. It is a dropdown menu that selects employee's name. Then it will automatically direct to leave_approve_process.php that will display any related information about the employee.

However, how can I change the code so that it will open leave_approve_process.php in a new tab. Please help me as I'm new to this javascript. Thanks.

$employee = mysqli_query("SELECT * FROM employee");

<script type="text/javascript">
function showUser()
{
    var str1=document.getElementById('employee').value;
    if (str1=="")
    {
        document.getElementById("txtHint").innerHTML="";
        return;
    } 
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
        xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","leave_approve_process.php?id="+str1,true);
    xmlhttp.send(); 
}
</script> 

<form name="form2" id="form2" method="post" action="">
<select name="employee" id="employee" onChange="showUser()" class="validate[required]">
    <option value="">Select one</option>
    <?php
    while($row_sem=mysqli_fetch_array($employee))
    {       
        echo "<option value='". $row_sem['emp_id'] ."'>". $row_sem['emp_name'] ."</option>";        
    }
    ?>
</select>
</form>
<br />
<div id="txtHint" align="center"></div>
amln_ndh
  • 617
  • 2
  • 9
  • 30

1 Answers1

1

Create a new function and call it from within your current function.

function OpenInNewTab("leave_approve_process.php?id="+str1,true) {
  var win = window.open("leave_approve_process.php?id="+str1,true, '_blank');
  win.focus();
}

You can find more relevant answers at Open a URL in a new tab (and not a new window) using JavaScript if my answer didn't work for you.

Community
  • 1
  • 1
Liam Macmillan
  • 388
  • 1
  • 5
  • 13