The following codes can be found in my javascript file (code.js):

        function addBranch(path, id){

            //Click "Cancel" button return to Restaurant Manager Page
            $("input[name=btCancel]").click(function(){
                window.location.href = path + '/branch_manager.php?id=' + id
            });
        }

The following codes can be found in my php file (test.php):

        <script src="<?php echo APP_WEB_PATH; ?>/js/jquery-1.11.1.min.js" type="text/javascript"></script>
        <script src="js/code.js"></script>
        <script>
            $(document).ready( addBranch('<?php echo APP_WEB_PATH ?>','<?php echo $_GET['id'] ?>') );
        </script>
        </head>
        <body>
        <input type="button" value="Cancel" name="btCancel">
        ....
        ....
        ....

When I attempt to click on the cancel button there is no action. Did I miss something? Your help is kindly appreciated.

Member Avatar for diafol

Check the browser console for an error. Bit confused as to why the event script is inside the function.

You can store the path inside a variable.

PHP

$qs = (isset($_GET['id'])) ? '?id=' . $_GET['id'] : '';

JS

<script>
var path = <?=APP_WEB_PATH?>;
var qs = '<?=$qs?>';

$("input[name=btCancel]").click(function(){
    window.location.href = path + '/branch_manager.php' + qs;
});
<script>
</body>

But that's horrible (mixing php/js)

var path = <?=APP_WEB_PATH?>; Is this a PHP code? Nope. I understand :)

It doesn't work. When I click on the cancel button there is no action. Also the

var qs = '<?=$qs?>';

cannot be obtained in the JS file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.