Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Passing variable to other JavaScript file

I have a TableView loaded from a SQLite db, and by tapping an item (iPhone) the users goes to another js document with content.

At this moment I load the content by querying the database with the window's title:

var rows = db.execute('SELECT info FROM MYTABLE 
WHERE name = "' + Titanium.UI.currentWindow.title + '" ');

Of course, this is not an ideal method. My question is therefore: how can I pass a parameter (like id) from the TableView data to the other JavaScript file?



— asked September 18th 2010 by Pieter Kubben
  • iphone
  • sql
  • tableview

3 Answers

  • Accepted Answer


    Just use this code:

    var newWindow = Titanium.UI.createWindow({  
        url: "details.js",
        info: "you informations for the new window"

    To recieve the parameter use:

    var win = Titanium.UI.currentWindow;


    — answered September 18th 2010 by Felix Krause
    1 Comment
    • Felix did give the correct answer, and also working for my goal. I found that I can add the parameter in the data.push() function (fetched from database) and then forward it to the new window from the e.rowData in the event handler (see pastie above). Solved!

      — commented September 21st 2010 by Pieter Kubben
  • Thanks! That works very well if I enter the content for info directly. One issue left: I retrieve data from a SQLite db and load them in a TableView.

    See here on Pastie for some code. As you see, I have been playing around a little.

    Question: how can I retrieve the content for info directly from the db? I cannot use e.index (no correlation with db), and I seemingly cannot add it to the data-array (iPhone simulator crashed in that case).

    The data for "info" are in rows.field(2) in the database. Hope that my explanation makes sense this way….

    — answered September 19th 2010 by Pieter Kubben
  • It would even be easier to use a global variable; e.g:
    Set a Global Variable first like this for a string: Ti.App.Properties.setString("NameAvariable","value");
    then output your variable in any js file you have like this: Ti.App.Properties.getString("yourVariableName");
    and at any time you can assign any value to your global variable.

    — answered August 11th 2012 by Talal Manaa
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.