Arrays


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Arrays

Hybrid View

  1. #1
    jon whitton Guest

    Arrays


    Does anyone know what's gone wrong here????
    Thanks JON
    <html>
    <head>
    <title>US States</title>
    </head>
    <body>
    <SCRIPT Language = "JavaScript">
    <!--
    function getStateDate() {
    var selectedState = document.entryForm.entry.value
    for ( var i = 0; i < USStates.length; i++) {
    if (USStates[i] == selectedState) {
    break
    }
    }
    alert("That state entered the union in " + stateEntered[i] + ".")
    }

    // -->
    </SCRIPT>
    <SCRIPT Language = "JavaScript">
    <!--
    var USStates = New Array(5)

    USStates[0] = "Alaska"
    USStates[1] = "Alabama"
    USStates[2] = "Arizona"
    USStates[3] = "Arkansas"
    USStates[4] = "Wyoming"

    Alert("the largest state is " + USStates[0] + ".")

    var stateEntered = New Array(5)

    stateEntered[0] = "1829"
    stateEntered[1] = "1859"
    stateEntered[2] = "1900"
    stateEntered[3] = "1910"
    stateEntered[4] = "1920"
    //-->
    </SCRIPT>
    <form>
    <input type="text" name="entryForm" value=" " size=14>
    <input type="button" value="find" onClick="getStateDate()">
    </form>
    </body>
    </html>

  2. #2
    mike m Guest

    Re: Arrays


    i just correct some of the mistakes you had in the script...but i'm not sure
    what you where trying to accomplish...

    I would move the script functions into the html head block if i were you
    but i'm guessing that you want to run the scripts upon start up.

    <html>
    <head>
    <title>US States</title>
    </head>
    <body>
    <SCRIPT Language = "JavaScript">
    <!--
    function getStateDate()
    { var selectedState = form1.entryForm.value;
    for ( var i = 0; i < USStates.length; i++)
    { if (USStates[i] == selectedState)
    { break;
    }
    }
    alert("That state entered the union in " + stateEntered[i] + ".");
    }

    // -->
    </SCRIPT>
    <SCRIPT Language = "JavaScript">
    <!--
    var USStates = new Array(5);

    USStates[0] = "Alaska";
    USStates[1] = "Alabama";
    USStates[2] = "Arizona";
    USStates[3] = "Arkansas";
    USStates[4] = "Wyoming";

    alert("the largest state is " + USStates[0] + ".");

    var stateEntered = new Array(5);

    stateEntered[0] = "1829";
    stateEntered[1] = "1859";
    stateEntered[2] = "1900";
    stateEntered[3] = "1910";
    stateEntered[4] = "1920";
    //-->
    </SCRIPT>
    <form name="form1">
    <input type="text" name="entryForm" value=" " size=14>
    <input type="button" value="find" onClick="getStateDate()">
    </form>
    </body>
    </html>








    "jon whitton" <jon@matherfold.freeserve.co.uk> wrote:
    >
    >Does anyone know what's gone wrong here????
    >Thanks JON
    ><html>
    ><head>
    ><title>US States</title>
    ></head>
    ><body>
    ><SCRIPT Language = "JavaScript">
    ><!--
    >function getStateDate() {
    > var selectedState = document.entryForm.entry.value
    > for ( var i = 0; i < USStates.length; i++) {
    > if (USStates[i] == selectedState) {
    >break
    > }
    >}
    > alert("That state entered the union in " + stateEntered[i] + ".")
    >}
    >
    >// -->
    ></SCRIPT>
    ><SCRIPT Language = "JavaScript">
    ><!--
    >var USStates = New Array(5)
    >
    > USStates[0] = "Alaska"
    > USStates[1] = "Alabama"
    > USStates[2] = "Arizona"
    > USStates[3] = "Arkansas"
    > USStates[4] = "Wyoming"
    >
    >Alert("the largest state is " + USStates[0] + ".")
    >
    >var stateEntered = New Array(5)
    >
    > stateEntered[0] = "1829"
    > stateEntered[1] = "1859"
    > stateEntered[2] = "1900"
    > stateEntered[3] = "1910"
    > stateEntered[4] = "1920"
    >//-->
    ></SCRIPT>
    ><form>
    ><input type="text" name="entryForm" value=" " size=14>
    ><input type="button" value="find" onClick="getStateDate()">
    ></form>
    ></body>
    ></html>



  3. #3
    Vikram Rajan Guest

    Re: Arrays


    Jon Boy,

    How about ending every Javascript statement with a semi-colon? Also dont
    capitalize letters. 'New' should be 'new', 'Alert' should be 'alert'. JavaScript
    is case sensitive.
    Try this now :

    <html>
    <head>
    <title>US States</title>
    </head>
    <body>
    <SCRIPT Language = "JavaScript">
    <!--
    function getStateDate()
    {
    var selectedState = document.entryForm.entry.value
    for ( var i = 0; i < USStates.length; i++)
    {
    if (USStates[i] == selectedState)
    {
    break;
    }
    }
    alert("That state entered the union in " + stateEntered[i] + ".");
    }

    // -->
    </SCRIPT>
    <SCRIPT Language = "JavaScript">
    <!--
    var USStates = new Array(5);

    USStates[0] = "Alaska";
    USStates[1] = "Alabama";
    USStates[2] = "Arizona";
    USStates[3] = "Arkansas";
    USStates[4] = "Wyoming";

    alert("the largest state is " + USStates[0] + ".");

    var stateEntered = new Array(5);

    stateEntered[0] = "1829";
    stateEntered[1] = "1859";
    stateEntered[2] = "1900";
    stateEntered[3] = "1910";
    stateEntered[4] = "1920";
    //-->
    </SCRIPT>
    <form>
    <input type="text" name="entryForm" value=" " size=14>
    <input type="button" value="find" onClick="getStateDate();">
    </form>
    </body>
    </html>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center