Hi

The following code is part of a program i have written:

for (var count = 1; count <= password.length-2; count = count + 1)
{
    document.write('*')

};

What i want is for the output of the above (which would be a number of characters the password is minus 2 shown in *) to not be written to the screen but to be added as a value to a variable.
Obviously document.write puts it on the screen. I want to be able to assign it to a variable, say 'code' and then i can use this elsewhere in my program.

Anyone know of a way.

Cheers

I haven't tested it out but you can try this am assuming this is what you are asking.

function getCode(password){
   var code="";
   for(var count=1; count<=password.length-2;count++){
      code+="*";
   }
return code;
}

You could then just call the function to assign the string to whatever. I think you could even print it straight.

document.write(getCode(theVarYouCalledPassword));

I repeat I haven't tested anything.

Thank you. That helped alot.

n33712

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.