0

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.

2
Contributors
3
Replies
18
Views
2 Years
Discussion Span
Last Post by solomon_13000
1

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)

0

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

Edited by solomon_13000

0

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.

Edited by solomon_13000

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.