Michael G's Blog

What’s this stuff mean?

Posted in Advanced Scripting by michaelg1980 on February 2, 2010

The Javascript File Code:

// initialize the counter and the array
var numnames=0;
var names = new Array();
function SortNames() {
// Get the name from the text field
// Add the name to the array
// Increment the counter
// Sort the array

The HTML Code:

<title>Array Sorting Example</title>
<script type=”text/javascript” language=”javascript” src=”sort.js”> <<This part links to the Javascript file above
<h1>Sorting String Arrays</h1>
<p>Enter two or more names in the field below,
and the sorted list of names will appear in the
text area.</p>
<form name=”theform”>  <<Here’s where the form is first identified so that the statement “document.theform…,” in the function SortNames, knows where to go and grab something.
<input type=”text” name=”newname” size=”20″>   <<This is the place the value “newname” is entered by the user and located by the  statment “thename=document.theform.newname.value;” in the function SortNames.
<input type=”button” name=”addname” value=”Add”
onclick=”SortNames();”> <<This is where the function SortNames is activated by user’s click.
<h2>Sorted Names</h2>
<textarea cols=”60″ rows=”10″ name=”sorted”>  <<Here, the text area “sorted” is identified, so the method “names.sort” knows where to put the data identified by the property below it: “document.theform.sorted.value=names.join(“\n”);”
The sorted names will appear here.

A Link to my first array!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: