Setting variable value (mosync native ui)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samvb
    New Member
    • Oct 2006
    • 228

    Setting variable value (mosync native ui)

    I had asked the mosync community but there seems to be an inactive community. The question is more javascript as well.

    I have a widget editBox defined as

    Code:
    <div data-widgetType="EditBox"
    						id="searchword"
    						data-width="FILL_AVAILABLE_SPACE"
    data-text=""data-fontSize="26">
    					</div>
    on top of my page is my javascript files (i.e. warmhole.js) and a custom function defined as follows

    Code:
    function getEntry(){
    var word2="";
     var searchtextctrl=document.getNativeElementById("searchword");
    //read its text property now then save it to word2 var
    				searchtextctrl.getProperty("text",
    				function(property,value)
    				 { 
    			word2=value;
    				},
    				function()
    				{
    			word2="";
    				}
    				);
    				
    
    }
    //if (!word2) { //tried as well (word=="")
    //no entry
    }
    The problem is word2 is blank. the line word2=value is working fine as its output is ok. But after it gets out of the getproperty function, word2 seems to be reset to blank. What am i missing?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    i aligned your code properly to understand what you were asking by looking at the code:

    Code:
    function getEntry() {
        var word2 = "";
        var searchtextctrl = document.getNativeElementById("searchword");
        
        //read its text property now then save it to word2 var
        searchtextctrl.getProperty("text", function(property, value) { 
                word2 = value;
            },
            function() {
                word2 = "";
            }
        );
    }
    
    
    if (!word2) { //tried as well (word=="")
        //no entry
    }
    when you have a close look at it - you define the variable word2 locally in the scope of your getEntry-function, thus you cannot access its value outside of it.

    Comment

    Working...