Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Run javascript on button click

By
scot77844
on 6/17/15, 5:54 AM 1,014 views

Hi,

I am having a button (say button1) in openerp form . I want to run a js file (say test.js). How can I run the js script on clicking the button.

This is same as my question https://www.odoo.com/nl_NL/forum/help-1/question/how-to-call-a-javascript-function-from-odoo-86782. I'm waiting any reply on either

Tarek Mohamed Ibrahim
on 6/17/15, 6:44 AM
0
Nedas Zilinskas
On 6/18/15, 8:26 AM

You would need to include your JS file (I assume you use Odoo v8).

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="assets_backend" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/your_module_name/static/src/js/test.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

Just not going deeper for this example we will select button by text inside it (not the best practice ofcourse). The code below is your test.js file content.

$(document).on('click', $('button:has(span:contains(Text Inside Button))'), function() {
    console.log('call function here');
});


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/17/15, 5:54 AM
Seen: 1014 times
Last updated: 6/18/15, 8:28 AM