facebook

custom.js

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #347938 Reply

    liortulip
    Member

    Hi Guys. I am new to using MobiOne and I read online that in order to program functions you should go to the file named projectname_custom.js. I opened this with notepad++, added a function, and saved the file. When I tried to use the function with a button in my app by typing the following code:
    whenPressed();
    Nothing happened. When I pasted the functions code directly into the button it worked fine. What am I doing wrong?

    Thanks!

    #347940 Reply

    Code_A
    Member

    In the Run Javascript box of the button, place the code:

    whenPressed();

    In the _custom.js file, place this code:

    function whenPressed(){
        alert('pressed!');
    }

    By the way, you can open/edit the _custom.js file directly in MobiOne.

    #347948 Reply

    liortulip
    Member

    Really? How do you do that. That would be so useful!

    By the way I just tried your recommendation and the program did nothing. Do I need to reopen the project after I make a change? Or are there any prerequisites, do I somehow have to link the file to the project?

    #347950 Reply

    Code_A
    Member

    Just add the code to the <project_name>_custom.js file and you should be good to go. Have you generated the files for your project? Once you do that the _custom.js file can be found in your project’s www folder.

    #347951 Reply

    liortulip
    Member

    I have, and I have managed to open it up in MobiOne. However, even using the exact code you gave me, the functions do not work.

    #347952 Reply

    Hi liortulip,

    See the next doc that suggests how to bind a javascript function with a widget:
    http://www.genuitec.com/mobile/docs/workingWithGeneratedFiles/workingWithGeneratedFiles.html#using_javascript_to_customize

    If after doing that it is not working it might be because you are adding your function in the wrong _custom.js file or there is a javascript error syntax on it so the function can’t be called.

    #347954 Reply

    Code_A
    Member

    I added the code above to the other example I posted for you. Hopefully this helps.

    Attachments:
    You must be logged in to view attached files.
Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: custom.js

You must be logged in to post in the forum log in