<!-- insert_names.html
The script in this document has an array of
names, name_list, whose values are in
alphabetic order. New names are input through
prompt. Each new name is inserted into the
name array, after which the new list is
displayed.
-->
<html>
<head>
<title>Name list </title>
</head>
<body>
<script type="text/javascript">
<!--
// The original list of names
var name_list = new Array("ahmad", "salem", "jaber", "fesal", "naser", "mohamad");
var new_name, index, last;
// Loop to get a new name and insert it
new_name = prompt("Please type a new name","")
last=name_list.lenght-1;
while (last >= 0 && name_list[last] > new_name)
{
name_list[last + 1] = name_list[last];
last = last - 1;
}
// Insert the new name into its spot in the array
name_list[last + 1] = new_name;
// Display the new array
document.write("<p><b>The new name list is:</b>",
"<br />");
for (index = 0; index < name_list.length; index++)
document.write(name_list[index], "<br />");
document.write("</p>");
//** end of the outer while loop
// -->
</script>
</body>
</html>