0

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.

8
  • 1
    provide a code of createElement function Commented Jan 22, 2015 at 14:10
  • 2
    What is createElement? Commented Jan 22, 2015 at 14:10
  • 1
    Which JavaScript framework is used in your project? I'd try cName: 'fsContinue', onclick: '...', (comma, not dot). Commented Jan 22, 2015 at 14:11
  • 1
    @OlegGrenrus I have tried the comma instead of the dot. But it is not working. It is now disregarding all the code in the js file. Commented Jan 22, 2015 at 14:19
  • 1
    All the information in the comments is way above my head. native global document object no clue what it all means. I am trying to learn as quick as I can by trial and error. But most of the time I learn from complete codes. Because somehow I can see the logic. Do not see this message as a negetive message. I just wanted to let everyone know that they are not commenting to an IT Guru but more to a rookie. Commented Jan 22, 2015 at 14:22

1 Answer 1

4

try something like this

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

hope this helps

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you. I only have one problem I have no idea how to implement your code. It is all new for me.
put it after element is created. after createElement() is called
` this.ctrlContinue = createElement( 'button', { cName : 'fs-continue', inner : 'Continue', appendTo : this.ctrls } ); this.ctrlContinue.onclick = function () { console.log('test'); }; this._showCtrl( this.ctrlContinue );` What should I write by console.log
I am sorry. instead of console.log('test'); you should write your code. javascript logic that should be executed when element, you created, is clicked.
So that is the original code not setBrowserFrameSource(); return false;
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.