weird problem with variable

Z

ziemon

// index.html

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

// index.html


// test.html

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

<body">
<SCRIPT type=text/javascript>
<!--
function player(number,name,position,height,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","Gary Payton","Guard"," 6'4","Oregon State")
var menu1_1 = new Array(2)
menu1_1[0] = new player("21","Pete Payton","Guard"," 6'4","Oregon State")
menu1_1[1] = new player("22","John Payton","Guard"," 6'4","Oregon State")
menu1[1] = new player("33","Hersey Hawkins","Guard"," 6'3","Bradley")
menu1[2] = new player("42","Vin Baker","Forward"," 6'11","Hartford")
menu1[3] = new player("11","Detlef Schrempf","Forward"," 6'10","
Washington")
menu1[4] = new player("22","Jim McIlvaine","Center"," 7'1"," Marquette")

var x = Request.QueryString("menu")

for (i = 0; i < x.length; i++)
{
document.write(x.number + x.name + x.height + x.position +
x.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 CSJSRequestObject.js can be found :
http://www.andrewu.co.uk/tools/request/
 
L

Lasse Reichstein Nielsen

ziemon said:
<SCRIPT src="CSJSRequestObject.js" type=text/javascript></SCRIPT>

You should put quotes around the type attibute value.

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

HTML comments are not needed in Javascript.
var x = Request.QueryString("menu")

Let's assume x now contains the string "menu1_1"
for (i = 0; i < x.length; i++)

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.
{
document.write(x.number + x.name + x.height + x.position +
x.college + "<br>")


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.Querystring to

var x = window[Request.QueryString("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.
y isn;t it working ?

Is it "y" or "x" that isn't working? [1]
if i do a check like :

if(x = "menu1")

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
 
R

Richard Cornford

y isn;t it working ?

Is it "y" or "x" that isn't working? [1]
<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 internationalisation, or acronyms.

Richard.
 
L

Lasse Reichstein Nielsen

Richard Cornford said:
y isn;t it working ?

Is it "y" or "x" that isn't working? [1]
<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?

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.
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.

Hear, hear!
[1] Not including abbreviations relating to the subject, such as "i18n"
for internationalisation, or acronyms.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top