By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,872 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,872 IT Pros & Developers. It's quick & easy.

Setting variable value (mosync native ui)

100+
P: 228
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

Expand|Select|Wrap|Line Numbers
  1. <div data-widgetType="EditBox"
  2.                         id="searchword"
  3.                         data-width="FILL_AVAILABLE_SPACE"
  4. data-text=""data-fontSize="26">
  5.                     </div>
  6.  
on top of my page is my javascript files (i.e. warmhole.js) and a custom function defined as follows

Expand|Select|Wrap|Line Numbers
  1. function getEntry(){
  2. var word2="";
  3.  var searchtextctrl=document.getNativeElementById("searchword");
  4. //read its text property now then save it to word2 var
  5.                 searchtextctrl.getProperty("text",
  6.                 function(property,value)
  7.                  { 
  8.             word2=value;
  9.                 },
  10.                 function()
  11.                 {
  12.             word2="";
  13.                 }
  14.                 );
  15.  
  16.  
  17. }
  18. //if (!word2) { //tried as well (word=="")
  19. //no entry
  20. }
  21.  
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?
Mar 4 '15 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,320
i aligned your code properly to understand what you were asking by looking at the code:

Expand|Select|Wrap|Line Numbers
  1. function getEntry() {
  2.     var word2 = "";
  3.     var searchtextctrl = document.getNativeElementById("searchword");
  4.  
  5.     //read its text property now then save it to word2 var
  6.     searchtextctrl.getProperty("text", function(property, value) { 
  7.             word2 = value;
  8.         },
  9.         function() {
  10.             word2 = "";
  11.         }
  12.     );
  13. }
  14.  
  15.  
  16. if (!word2) { //tried as well (word=="")
  17.     //no entry
  18. }
  19.  
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.
Mar 13 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.