defining and accessing js objects.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry A. Haimann

    defining and accessing js objects.

    First of all be kind, I am new to javascript.

    In the following page, can you tell me if I have defined the ObjTyp and
    the ObjTypeCnt incorrectly. And if that is correct, why can't they be
    seen from within my function ChangeSearch? Yes, the ObjTyp and ObjTypeCnt
    are generated by a php script.

    Thx in advance, Terry


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script LANGUAGE=JavaSc ript>
    var ObjType = new array(
    "Binary",
    "Emis",
    "Gal",
    "Glob",
    "Open",
    "Open&Ems",
    "Plan",
    "Planet",
    "SuprNovRem ",
    "");
    var ObjTypeCnt = 9;


    function ChangeSearch(sr chstr)
    {

    i = document.SrchFo rm.SearchDB.val ue;
    alert('Testing 1... ' + document.SrchFo rm.SearchDB.val ue)
    // alert('Testing 2... ' + document.SrchFo rm.SearchDB.opt ions[i].text)
    if (i==2)
    {
    j = 0;
    alert("ObjTypeC nt = " + ObjTypeCnt);
    while (j < ObjTypeCnt)
    {
    var myNewOption = new option(j+1, ObjType[j]);
    document.SrchFo rm.DetailDB.opt ions[0] = myNewOption;
    alert("j = " + j);
    j++;
    }
    }
    }

    </SCRIPT>
    <title>Astronom y Page</title>
    <meta http-equiv="content-type"
    content="text/html; charset=ISO-8859-1">
    </head>
    <body>

    <div align="center"> <big><big><big> <big><big>Terry 's Astronomy Page</big></big></big></big></big><br>
    <form NAME=SrchForm>

    <select NAME="SearchDB"
    onChange="Chang eSearch()">
    <option VALUE=0 SELECTED> Search By
    <option VALUE=1>Object
    <option VALUE=2>Type of Object
    <option VALUE=3>Photogr apher
    </select>
    <select NAME="DetailDB" >
    </select>
    </div>
    <br>
    <br>
    </form>
    </body>
    </html>
  • lallous

    #2
    Re: defining and accessing js objects.

    Hi,

    A quick look at your code reveals some syntax typos:

    array is different than 'Array' so change to 'Array'.
    Same applies for 'option' =>change to: 'Option'

    --
    Elias
    "Terry A. Haimann" <terry@yngstr.o ldboy.com> wrote in message
    news:pan.2003.0 9.08.00.35.58.2 22537@yngstr.ol dboy.com...[color=blue]
    > First of all be kind, I am new to javascript.
    >
    > In the following page, can you tell me if I have defined the ObjTyp and
    > the ObjTypeCnt incorrectly. And if that is correct, why can't they be
    > seen from within my function ChangeSearch? Yes, the ObjTyp and ObjTypeCnt
    > are generated by a php script.
    >
    > Thx in advance, Terry
    >
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    > <html>
    > <head>
    > <script LANGUAGE=JavaSc ript>
    > var ObjType = new array(
    > "Binary",
    > "Emis",
    > "Gal",
    > "Glob",
    > "Open",
    > "Open&Ems",
    > "Plan",
    > "Planet",
    > "SuprNovRem ",
    > "");
    > var ObjTypeCnt = 9;
    >
    >
    > function ChangeSearch(sr chstr)
    > {
    >
    > i = document.SrchFo rm.SearchDB.val ue;
    > alert('Testing 1... ' + document.SrchFo rm.SearchDB.val ue)
    > // alert('Testing 2... ' + document.SrchFo rm.SearchDB.opt ions[i].text)
    > if (i==2)
    > {
    > j = 0;
    > alert("ObjTypeC nt = " + ObjTypeCnt);
    > while (j < ObjTypeCnt)
    > {
    > var myNewOption = new option(j+1, ObjType[j]);
    > document.SrchFo rm.DetailDB.opt ions[0] = myNewOption;
    > alert("j = " + j);
    > j++;
    > }
    > }
    > }
    >
    > </SCRIPT>
    > <title>Astronom y Page</title>
    > <meta http-equiv="content-type"
    > content="text/html; charset=ISO-8859-1">
    > </head>
    > <body>
    >
    > <div align="center"> <big><big><big> <big><big>Terry 's Astronomy[/color]
    Page</big></big></big></big></big><br>[color=blue]
    > <form NAME=SrchForm>
    >
    > <select NAME="SearchDB"
    > onChange="Chang eSearch()">
    > <option VALUE=0 SELECTED> Search By
    > <option VALUE=1>Object
    > <option VALUE=2>Type of Object
    > <option VALUE=3>Photogr apher
    > </select>
    > <select NAME="DetailDB" >
    > </select>
    > </div>
    > <br>
    > <br>
    > </form>
    > </body>
    > </html>[/color]


    Comment

    Working...