Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
![]() |
•
•
Join Date: May 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
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.
can someone explain to me what I am doing wrong and what I should 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 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 7:17 pm.
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.
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
•
•
Join Date: May 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
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.
If that is what you are stating that is now what I done but it is not functioning.
•
•
•
•
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.
•
•
Join Date: May 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
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.
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;
}
}![]() |
Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
- Displaying Hello and "Persons Name" (C++)
- new window? target="_blank" ? (JavaScript / DHTML / AJAX)
- my program is compiled.but on run that i have message "Exception in thread "main" jav (Java)
- After 2nd element read... cout is "scattered" (C++)
- total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast" (C++)
- The definiton of "Memory leaks" (C++)
- Deitel's "C++ How To Program" exercise 2.18 (C++)
- beginner"problem in arrays help me in codes" (C)
- "Error Message - tried to execute invalid instruction" (C++)
- loop in main function to an "if" statement (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Hiding options
- Next Thread: checkbox - unchek
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode