User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 430,112 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,211 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 917 | Replies: 2 | Solved
Reply
Join Date: Jan 2008
Posts: 11
Reputation: n33712 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
n33712 n33712 is offline Offline
Newbie Poster

Assign count output to a variable!

  #1  
Jan 29th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Location: Brownsville or Austin, TX or Faber, VA
Posts: 59
Reputation: world_weapon is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
world_weapon's Avatar
world_weapon world_weapon is offline Offline
Junior Poster in Training

Re: Assign count output to a variable!

  #2  
Jan 29th, 2008
I haven't tested it out but you can try this am assuming this is what you are asking.
  1. function getCode(password){
  2. var code="";
  3. for(var count=1; count<=password.length-2;count++){
  4. code+="*";
  5. }
  6. return code;
  7. }

You could then just call the function to assign the string to whatever. I think you could even print it straight.
  1. document.write(getCode(theVarYouCalledPassword));
I repeat I haven't tested anything.
The purpose of my existence is why I am here.
Reply With Quote  
Join Date: Jan 2008
Posts: 11
Reputation: n33712 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
n33712 n33712 is offline Offline
Newbie Poster

Re: Assign count output to a variable!

  #3  
Jan 30th, 2008
Thank you. That helped alot.

n33712
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:10 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC