By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,359 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,359 IT Pros & Developers. It's quick & easy.

weird problem with variable

P: n/a
// 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[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 CSJSRequestObject.js can be found :
http://www.andrewu.co.uk/tools/request/
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"ziemon" <ne**@ziemon.nl> writes:
<SCRIPT src="CSJSRequestObject.js" type=text/javascript></SCRIPT>
You should put quotes around the type attibute value.
<body">
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[i].number + x[i].name + x[i].height + x[i].position +
x[i].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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:zn**********@hotpop.com...
<snip>
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.
Jul 20 '05 #3

P: n/a
"Richard Cornford" <ri*****@litotes.demon.co.uk> writes:
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:zn**********@hotpop.com...
<snip>
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.