How to pass a parameter in a Javascript confirm function?

Posted by Miles M. on Stack Overflow See other posts from Stack Overflow or by Miles M.
Published on 2012-10-02T21:34:38Z Indexed on 2012/10/02 21:37 UTC
Read the original article Hit count: 135

Filed under:
|
|

I have something like that in my code:

<?php foreach($clients as $client): ?>
                <tr class="tableContent">
                    <td onclick="location.href='<?php echo site_url('clients/edit/'.$client->id ) ?>'"><?php echo $client->id ?></td>
                    <td><a class='Right btn btn-danger' onClick="ConfirmMessage('client', <?php $client->id ?>,'clients')">
                        <i class="icon-remove-sign icon-white"></i>
                    </a></td>
                </tr>
            <?php endforeach  ?>

that's actually the view. So when the user click on the delete button (thr one with the btn-danger class) I'd like him to confirm his choice with a javascript confirmation box message. You can find that script in the header

    <script>
    function ConfirmMessage(type, id, types) {
        if (confirm("Are you sure you want to delete this ",type," ?")) { // Clic sur OK
           document.location.href='<?php echo site_url(); ?>',types,'/delete/',id;
        }
    }
    </script>

So here is my question:

I would like the $type to be replaced by a paramenter (like client, article, post .. ) that I'll pass to the function. And i would like to get the $client->id parameter as well. I'm bad in javascript and as you already have guess, It is obviously not working at all.

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript