weird problem with variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ziemon

    weird problem with variable

    // index.html

    <a href="test.html ?menu=menu1">me nu1</a>
    <a href="test.html ?menu=menu1_1"> menu1_1</a>

    // index.html


    // test.html

    <html>
    <head>
    <title>Untitled </title>
    <SCRIPT src="CSJSReques tObject.js" type=text/javascript></SCRIPT>
    </head>

    <body">
    <SCRIPT type=text/javascript>
    <!--
    function player(number,n ame,position,he ight,college)
    {
    this.number = number
    this.name = name
    this.position = position
    this.height = height
    this.college = college
    }

    var menu1 = new Array(5)
    menu1[0] = new player("20","Ga ry Payton","Guard" ," 6'4","Oregon State")
    var menu1_1 = new Array(2)
    menu1_1[0] = new player("21","Pe te Payton","Guard" ," 6'4","Oregon State")
    menu1_1[1] = new player("22","Jo hn Payton","Guard" ," 6'4","Oregon State")
    menu1[1] = new player("33","He rsey Hawkins","Guard "," 6'3","Bradley" )
    menu1[2] = new player("42","Vi n Baker","Forward "," 6'11","Hartford ")
    menu1[3] = new player("11","De tlef Schrempf","Forw ard"," 6'10","
    Washington")
    menu1[4] = new player("22","Ji m McIlvaine","Cen ter"," 7'1"," Marquette")

    var x = Request.QuerySt ring("menu")

    for (i = 0; i < x.length; i++)
    {
    document.write( x[i].number + x[i].name + x[i].height + x[i].position +
    x[i].college + "<br>")
    }
    // -->
    </script>
    </body>
    </html>

    // test.html


    y isn;t it working ?
    if i do a check like :

    if(x = "menu1")
    {
    alert("ok")
    }

    it shows its there
    additional info about CSJSRequestObje ct.js can be found :



  • Lasse Reichstein Nielsen

    #2
    Re: weird problem with variable

    "ziemon" <news@ziemon.nl > writes:
    [color=blue]
    > <SCRIPT src="CSJSReques tObject.js" type=text/javascript></SCRIPT>[/color]

    You should put quotes around the type attibute value.
    [color=blue]
    > <body">[/color]

    The quote is misplaced here.
    [color=blue]
    > <SCRIPT type=text/javascript>
    > <!--[/color]

    HTML comments are not needed in Javascript.
    [color=blue]
    > var x = Request.QuerySt ring("menu")[/color]

    Let's assume x now contains the string "menu1_1"
    [color=blue]
    > for (i = 0; i < x.length; i++)[/color]

    Then "x.length" is 7, the length of the string "menu1_1". The value of
    "x" is a string, not the array stored in the variable with the same
    name as x's value.
    [color=blue]
    > {
    > document.write( x[i].number + x[i].name + x[i].height + x[i].position +
    > x[i].college + "<br>")[/color]

    So this fails, since "x" has no property called "1" (or if it does, it
    is a single character string which won't have properties called "number",
    "name" etc.).

    What you can do, is to change the call to Request.Queryst ring to

    var x = window[Request.QuerySt ring("menu")];

    Then it lets "x" be the value of the global variable whose name is in
    the querystring, which is what I assume you want.
    [color=blue]
    > y isn;t it working ?[/color]

    Is it "y" or "x" that isn't working? [1]
    [color=blue]
    > if i do a check like :
    >
    > if(x = "menu1")[/color]

    That is not a test, it is an assignment that assigns the string value
    "menu1" to the variable "x". The result is converted to a boolean for
    use in the "if", and it gives true (it is a non-empty string).

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Richard Cornford

      #3
      Re: weird problem with variable

      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:znhgv0u7.f sf@hotpop.com.. .
      <snip>[color=blue][color=green]
      > > y isn;t it working ?[/color]
      >
      > Is it "y" or "x" that isn't working? [1][/color]
      <snip>

      :)

      Were you planning a footnote suggesting that abbreviations [1] (even
      when in common use in British, North American or Antipodean, etc. (or
      any of their national/cultural sub groups) English) are inappropriate on
      an international newsgroup where many of the regular contributors write
      English as a second (or third+) language?

      I loathe these "text message" abbreviations. They may be excused when
      the input device is a telephone dialling pad but otherwise I take a
      posters unwillingness to type in those extra letters as sufficient
      reason not to bother answering.

      [1] Not including abbreviations relating to the subject, such as "i18n"
      for internationalis ation, or acronyms.

      Richard.


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: weird problem with variable

        "Richard Cornford" <richard@litote s.demon.co.uk> writes:
        [color=blue]
        > "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
        > news:znhgv0u7.f sf@hotpop.com.. .
        > <snip>[color=green][color=darkred]
        > > > y isn;t it working ?[/color]
        > >
        > > Is it "y" or "x" that isn't working? [1][/color]
        > <snip>
        >
        > :)
        >
        > Were you planning a footnote suggesting that abbreviations [1] (even
        > when in common use in British, North American or Antipodean, etc. (or
        > any of their national/cultural sub groups) English) are inappropriate on
        > an international newsgroup where many of the regular contributors write
        > English as a second (or third+) language?[/color]

        That is exactly what I were, just in fewer words (since English is my
        second language, I am not as fluent in it, as I am in my first
        language).

        I am quite capable of deciphering most single-letter abbreviations,
        but it does take more time to comprehend, than the correct spelling
        would. Mostly, it just annoys me to see the language mistreated like
        that.
        [color=blue]
        > I loathe these "text message" abbreviations. They may be excused when
        > the input device is a telephone dialling pad but otherwise I take a
        > posters unwillingness to type in those extra letters as sufficient
        > reason not to bother answering.[/color]

        Hear, hear!
        [color=blue]
        > [1] Not including abbreviations relating to the subject, such as "i18n"
        > for internationalis ation, or acronyms.[/color]

        I don't like l18n either. It attempts, too hard, to be "cute", and I
        just find it plain annoying. It's only 20 letters. If that is too hard
        for someone to type, they can make a macro. It doesn't help when it is
        contagious (witness "l10n" - localization).
        But why should abbreviations be exempt from Sturgeon's law: 90% of
        everything is c2p.

        No, I don't like recursive acronyms either. "GNU" was fun. The rest
        are pale immitations.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...