purple11111
purple11111

Reputation: 719

onclick inside javascript function

I am working on a project and in this project I got the following code inside a .js file.

    // continue button (jump to next field)
    this.ctrlContinue = createElement( 'button', { cName : 'fs-continue', inner : 'Continue', appendTo : this.ctrls } );
    this._showCtrl( this.ctrlContinue );

I need to add onclick="setBrowserFrameSource(); return false;" to the above code. I have tried:

cName : 'fs-continue' . 'onclick="setBrowserFrameSource(); return false;"', But this did not work!

Thanks for helping.

Here some more code as asked in the comments:

    /**
 * addControls function
 * create and insert the structure for the controls
 */
FForm.prototype._addControls = function() {
    // main controls wrapper
    this.ctrls = createElement( 'div', { cName : 'fs-controls', appendTo : this.el } );

Thanks to the answer from Rafail Akhmetshin I have changed the code to the following:

        this.ctrlContinue = createElement( 'button', { cName : 'fs-continue', inner : 'Continue', appendTo : this.ctrls } );
    this.ctrlContinue.onclick = function () {
        console.log('test');
    };      
    this._showCtrl( this.ctrlContinue );

Now my instinct says I need to do something with this console.log('test'); But what? Do I need to change this into setBrowserFrameSource(); return false; or should I add the code into the original function?

Thanks everyone for helping.

Upvotes: 0

Views: 1633

Answers (1)

X A
X A

Reputation: 837

try something like this

this.ctrlContinue.onclick = function () {
    // your code here.
};

hope this helps

Upvotes: 4

Related Questions