Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Array of "hope??"

Reply
Thread Tools

Array of "hope??"

 
 
Rich
Guest
Posts: n/a
 
      03-18-2005
I am close than I was before and I thank y'all for your Great Help!!

I wrote the following script with help.

So far it does what I want, it will prompt user for Input, then Display the
User's inputted information in a Table using the document.write. Which is
great.

The only thing I'm not understanding is how to have it display the amount of
Strings and Numbers in a table.

I thought the document.write(isNaN(parseInt (myArray[1]))) would display the
info but it only comes up with a True or False reply. (see script below)

Any help would be GREATLY appreicated.

Rich


<HTML>
<HEAD>
<TITLE>Array Man</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = JavaScript>
var myArray = [];
myArray[0] = [];
myArray[0][0] = prompt ("Enter First Name:", " ");
myArray[0][1] = prompt ("Enter Last Name:", " ");
myArray[0][2] = prompt ("Enter City you currently live in:", " ");

myArray[1] = [];
myArray[1][0] = prompt ("Enter Zip Code:", " ");
myArray[1][1] = prompt ("Enter your Age:", " ");
myArray[1][2] = prompt ("Enter Number of Years in College:", " ");

var row;
var column;

document.write("<table width=\"25%\" border=\"1\" align=\"center\"
cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"ddffff\">");

document.write("<tr>");
for (column in myArray[0])
{
document.write("<td>" + myArray[0][column] + "</td>");
}
document.write("</tr><tr>");
for (column in myArray[1])
{
document.write("<td>" + myArray[1][column] + "</td>");
}
document.write("</tr>");
document.write("</table>");
document.write(isNaN(parseInt (myArray[1])))
</script>
</body>
</html>


 
Reply With Quote
 
 
 
 
Diego Vilar
Guest
Posts: n/a
 
      03-18-2005
That's because isNaN only return boolean (true or false).

What do u wanna print with document.write(isNaN(parseInt (myArray[1])))
? The number of elements in myArray[1]? I don't get it...

 
Reply With Quote
 
 
 
 
Rich
Guest
Posts: n/a
 
      03-18-2005
What my script does right now is [

creates a multi-dimensional array, populates the array with values entered
by the user. And then it Displays the result on an HTML page in a tabular
format using the document.write() method.


I then want it to Display the counts of strings and numbers below the table.

I am trying to use the the NaN function to determine how many strings and
numbers are entered in by the User and can not figure this out.


I've been working on this for 3 days now and have not figured out what it is
I need to do, or not to do.

Any help, would be Greatly appreciated.

THANKS,
Richard


"Rich" <> wrote in message
news:tgF_d.38$191.7@trnddc02...
>I am close than I was before and I thank y'all for your Great Help!!
>
> I wrote the following script with help.
>
> So far it does what I want, it will prompt user for Input, then Display
> the User's inputted information in a Table using the document.write. Which
> is great.
>
> The only thing I'm not understanding is how to have it display the amount
> of Strings and Numbers in a table.
>
> I thought the document.write(isNaN(parseInt (myArray[1]))) would display
> the info but it only comes up with a True or False reply. (see script
> below)
>
> Any help would be GREATLY appreicated.
>
> Rich
>
>
> <HTML>
> <HEAD>
> <TITLE>Array Man</TITLE>
> </HEAD>
> <BODY>
> <SCRIPT LANGUAGE = JavaScript>
> var myArray = [];
> myArray[0] = [];
> myArray[0][0] = prompt ("Enter First Name:", " ");
> myArray[0][1] = prompt ("Enter Last Name:", " ");
> myArray[0][2] = prompt ("Enter City you currently live in:", " ");
>
> myArray[1] = [];
> myArray[1][0] = prompt ("Enter Zip Code:", " ");
> myArray[1][1] = prompt ("Enter your Age:", " ");
> myArray[1][2] = prompt ("Enter Number of Years in College:", " ");
>
> var row;
> var column;
>
> document.write("<table width=\"25%\" border=\"1\" align=\"center\"
> cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"ddffff\">");
>
> document.write("<tr>");
> for (column in myArray[0])
> {
> document.write("<td>" + myArray[0][column] + "</td>");
> }
> document.write("</tr><tr>");
> for (column in myArray[1])
> {
> document.write("<td>" + myArray[1][column] + "</td>");
> }
> document.write("</tr>");
> document.write("</table>");
> document.write(isNaN(parseInt (myArray[1])))
> </script>
> </body>
> </html>
>



 
Reply With Quote
 
Diego Vilar
Guest
Posts: n/a
 
      03-19-2005
You need to test all elements of the array. For example:

<HTML>
<HEAD>
<TITLE>Array Man</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = JavaScript>

var myArray = [];
myArray[0] = [];
myArray[0][0] = prompt ("Enter First Name:", " ");
myArray[0][1] = prompt ("Enter Last Name:", " ");
myArray[0][2] = prompt ("Enter City you currently live in:", " ");

myArray[1] = [];
myArray[1][0] = prompt ("Enter Zip Code:", " ");
myArray[1][1] = prompt ("Enter your Age:", " ");
myArray[1][2] = prompt ("Enter Number of Years in College:", " ");

var row;
var column;
var totNum = 0;
var totStr = 0;

document.write("<table width=\"25%\" border=\"1\" align=\"center\"
cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"ddffff\">");

document.write("<tr>");
for (column in myArray[0]) {

document.write("<td>" + myArray[0][column] + "</td>");
if (isNaN(parseInt(myArray[0][column]))) {
totStr++;
} else {
totNum++;
}
}

document.write("</tr><tr>");
for (column in myArray[1]) {
document.write("<td>" + myArray[1][column] + "</td>");
if (isNaN(parseInt(myArray[1][column]))) {
totStr++;
} else {
totNum++;
}
}

document.write("</tr>");
document.write("</table>");
document.write(totStr + "<br>" + totNum);
</script>
</body>
</html>

 
Reply With Quote
 
Rich
Guest
Posts: n/a
 
      03-19-2005
Hello Thanks for the info.

I tried this "as is" and keep getting an error.

Unfortunate for me, I'm not versed enough in JavaScript to know why it's
erroring out. bummer.

I'm not totally following the additional script either.

Any other help would be appreciated?


"Diego Vilar" <> wrote in message
news: ups.com...
> You need to test all elements of the array. For example:
>
> <HTML>
> <HEAD>
> <TITLE>Array Man</TITLE>
> </HEAD>
> <BODY>
> <SCRIPT LANGUAGE = JavaScript>
>
> var myArray = [];
> myArray[0] = [];
> myArray[0][0] = prompt ("Enter First Name:", " ");
> myArray[0][1] = prompt ("Enter Last Name:", " ");
> myArray[0][2] = prompt ("Enter City you currently live in:", " ");
>
> myArray[1] = [];
> myArray[1][0] = prompt ("Enter Zip Code:", " ");
> myArray[1][1] = prompt ("Enter your Age:", " ");
> myArray[1][2] = prompt ("Enter Number of Years in College:", " ");
>
> var row;
> var column;
> var totNum = 0;
> var totStr = 0;
>
> document.write("<table width=\"25%\" border=\"1\" align=\"center\"
> cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"ddffff\">");
>
> document.write("<tr>");
> for (column in myArray[0]) {
>
> document.write("<td>" + myArray[0][column] + "</td>");
> if (isNaN(parseInt(myArray[0][column]))) {
> totStr++;
> } else {
> totNum++;
> }
> }
>
> document.write("</tr><tr>");
> for (column in myArray[1]) {
> document.write("<td>" + myArray[1][column] + "</td>");
> if (isNaN(parseInt(myArray[1][column]))) {
> totStr++;
> } else {
> totNum++;
> }
> }
>
> document.write("</tr>");
> document.write("</table>");
> document.write(totStr + "<br>" + totNum);
> </script>
> </body>
> </html>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
How to combine 2 int Array into ONE int Array ? S300 Java 4 08-19-2003 07:04 PM
hashed array in array need the keys... and length Daniel Perl 1 08-14-2003 06:49 PM



Advertisments