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 402,620 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 2,294 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: 427 | Replies: 3
Reply
Join Date: May 2008
Posts: 11
Reputation: jennifer_48219 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
jennifer_48219 jennifer_48219 is offline Offline
Newbie Poster

I am new here..Can someone help with "Arrays"

  #1  
May 25th, 2008
Hi everyone I am new to javascript arrays and understand it just a little but need some help.
I have created an empty array name Numbers. I will use Numbers for all of my functions, therefore, I made it a global variable.

Then I created a function named FillArray. The purpose of this function is to get the last number out of the textbox and stick it into a variable called LastNumber.

When I get the "number" from the textbox, I need to convert it to a true number variable. Last but not least I need to use a while loop to fill the array with a bunchof numbers, starting with ) and ending with LastNumber.

This is what I have but I am not confident with it.
var Numbers = new Array();
var LastNumber;
var i;

var LastNumber = Numbers[Numbers.length-1];
function FillArray()
i = 0;
while (i < LastNumber) {
  document.frmMain.txtaOutput.value = (Numbers[i]);
  i = i + 1;
}

can someone explain to me what I am doing wrong and what I should do?
Last edited by jennifer_48219 : May 25th, 2008 at 6:17 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,537
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 111
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: I am new here..Can someone help with "Arrays"

  #2  
May 25th, 2008
You are making a copy of the array with your function declaration. Then, when you return from the function, the copy is not copied back to the original.

Either address the array globally (don't use it as a paramet4er, but just use it inside the function), or return it in the return statement.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: May 2008
Posts: 11
Reputation: jennifer_48219 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
jennifer_48219 jennifer_48219 is offline Offline
Newbie Poster

Re: I am new here..Can someone help with "Arrays"

  #3  
May 25th, 2008
I am sorry I am not understanding, can you explain to me in simpier term. I am very new to this. What I am understanding, you are saying don't use Numbers which is my array in my function leave it alone globally right.

If that is what you are stating that is now what I done but it is not functioning.

Originally Posted by MidiMagic View Post
You are making a copy of the array with your function declaration. Then, when you return from the function, the copy is not copied back to the original.

Either address the array globally (don't use it as a paramet4er, but just use it inside the function), or return it in the return statement.
Reply With Quote  
Join Date: May 2008
Posts: 11
Reputation: jennifer_48219 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
jennifer_48219 jennifer_48219 is offline Offline
Newbie Poster

Re: I am new here..Can someone help with "Arrays"

  #4  
May 26th, 2008
Okay I been working with this code can someone tell me if I am doing it right?
This is what I am trying to do: I have created an empty array name Numbers. I will use Numbers for all of my functions, therefore, I made it a global variable.

Then I created a function named FillArray. The purpose of this function is to get the last number out of the textbox and stick it into a variable called LastNumber.

When I get the "number" from the textbox, I need to convert it to a true number variable. Last but not least I need to use a while loop to fill the array with a bunch of numbers, starting with 0 and ending with LastNumber.

var Numbers = new Array();
var LastNumber;
var len;
var i;


function FillArray()
len=document.frmMain.txtaOutput.value.length;
LastNumber=document.frmMain.txtaOutput.value.FillArray(len-1); 
{
i = 0;
while (i < LastNumber) {
  document.frmMain.txtaOutput.value = (Numbers[i]);
  i = i + 1;
}
}
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 1:11 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC