Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LazyBrush

macrumors newbie
Original poster
Hello there,

I've made a simple Dashcode app which works fine on iOS devices.
It works fine in the Android emulator running on OSX. Yet on the
actual Nexus 7 device with chrome it has a strange error.

I have a Password Field which when typed into calls a bit of Javascript
to do a change 'My Pass' -> '** Pass' -> '*******'.

On the Nexus device it does this '*' -> 'M*' -> 'My*' -> 'My Pas*'.

Any ideas what I'm doing wrong?

LB

Code:
function passwordCharChange(event)
{
    var newstr;
    
    //
    // txt - Text in edit box so far
    //
    var textFieldValue = document.getElementById("textField");
    var txt = textFieldValue.value;

    //
    // len - Length of Saved password so far
    //
    var len = g_pw.length;
    
    while ( txt.length > g_pw.length)
    {
      // 
      // There is (still) more text in the edit field than in Saved PW.
      //
      
      //console.log( "Change: g_pw " + g_pw + " text field " + txt );
      
      //
      // Add 1 char to the end of Saved PW.
      //
      g_pw = g_pw + txt.charAt(len);
      
      //
      // substr(start,length) returns a sub string.
      // Replace one character in the textField with '*'
      //
      newstr = txt.substr(0,len) + '*' + txt.substr(len+1);
      
      //
      // update temp values
      //
      txt = newstr;
      len = g_pw.length;
    }
    
    if (g_pw.length > txt.length)
    {
      //
      // Saved PW is bigger than in textField.  So truncate it.
      //
      g_pw = g_pw.substr(0, txt.length);
    }
    
    //
    // Set modified text back into textField
    //
    textFieldValue.value = txt;
    
}
 
Got this working.

Added -

var lotsofstars="******************";

Changed line -

newstr = lotsofstars.substr(0,len) + '*' + txt.substr(len+1);

Worked but strangely on Nexus 7 doing a delete then caused
the password to be clear again, i.e. "****" ---delete--> "huh"

So looks like -
txt = textFieldValue.value;
... some other stuff ...
textFieldValue.value = txt;

Would actually put g_pw into textFieldValue.value.

Again fixed by setting txt to be *s of desired length and setting back
into textFieldValue.value.

So there is something weird in Android (different to iOS anyway) which
I don't quite understand but have to work round.

LB
 
In your function as posted here you first reference g_pw as:

Code:
var len = g_pw.length;

Is it a global variable? If not, I'm darned confused as to what it stores, so length would be zero or an error as variable not defined on strict consoles. Thanks for posting what else you fixed, but I don't see how it works at all with this issue.
 
Hi,

Yes, it's a global variable, initialised to "".
(I didn't include all the code, just the call back function.)

g_pw (Global _ PassWord )

Basically we have -
The visible Text Field (input : from user typing)
The visible Text Field (output : change text to stars '*')
g_pw (global saved password for use later in the code)

This function is called for each new letter added to the field.

thanks

LB

In your function as posted here you first reference g_pw as:

Code:
var len = g_pw.length;

Is it a global variable? If not, I'm darned confused as to what it stores, so length would be zero or an error as variable not defined on strict consoles. Thanks for posting what else you fixed, but I don't see how it works at all with this issue.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.