简体   繁体   中英

Open new window using html button and script

i have create simple leave application system. this system would receive staff leave application, then their head of department will approve the leave application. after that, human resource department can view monthly leave which is can list all staff leave on selected month.

my problem occur on this part. when HR view the monthly leave, then HR want to view leave details by clicking button (View Details) as picture that i have created, the system will show the last details only although i click on 1st row.

HR interface when view monthly leave

here my code...

                <tr><td> <?php echo $row['ID']; ?></td><td> <?php echo $row['staffname']; ?></td><td> <?php echo $row['noapply']; ?></td>
                <td><button onclick="myFunction()">View Details</button></td></tr>
                <script>
                function myFunction() {
                window.open("hrviewdatedetails.php?ID=<?php echo $row['LeaveID']; ?>", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=100, width=800, height=500");
                }
                </script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                $("#btnext").click(function () {                    
                    window.open("HTMLPage.htm", "PopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
                });
            });
</script>

Pass levae Id as argument in myFunction(LevId). and write the javascript code at the bottom of the page.

your code should look like this.

<tr><td> <?php echo $row['ID']; ?></td><td> <?php echo $row['staffname']; ?></td><td> <?php echo $row['noapply']; ?></td>
    <td><button onclick="myFunction(<?php echo $row['LeaveID']; ?>)">View Details</button></td></tr>

</tr>

<script>
    function myFunction(levID) {
        window.open("hrviewdatedetails.php?ID="+levID, "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=100, width=800, height=500");
    }
</script>

You can pass id in function . try this

            <td><button onclick="myFunction('<?php echo $row['ID']; ?>')">View Details</button></td></tr>
            <script>
            function myFunction(id) {
            window.open("hrviewdatedetails.php?ID="+id, "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=100, width=800, height=500");
            }
            </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM