/    Sign up×
Community /Pin to ProfileBookmark

can’t get this right

Could you please help me with this script and tell me why it doesn’t work:

<html>
<head>
<TITLE>Hope it works</TITLE>

</head>
<body bgcolor=”#FFFFFF” text=”#000000″ link=”#0000EE” vlink=”#551A8B”>
<script language=”javascript”>
<!–//
var channels = new Object();
channels[‘ANL’] = 15;

var channel_num = channels[ param(‘channel’) ];
if (channel_num == undefined)
alert(“error: invalid channel”);
else
window.location.href = channel_num + “.html”;
//–>
</script>
<a href=”http://americaspastime.tripod.com/trying/index.htm?page=ANL”>Works?</a>
</body>
</html>

My [URL=website]http://americaspastime.tripod.com/trying/[/URL] is here.
-Thanks

to post a comment
JavaScript

18 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 19.2003 — The obvoius error would be here...

channels[ param('channel') ];

you have this object array channels and you are passing it a value

which should be returned vrom the function param('channel')

however I don't see a function named

param('channel')

in your code...
Copy linkTweet thisAlerts:
@chrismartzauthorJun 19.2003 — I have this code which is suposed to work but it doesn't. Could someone help me. Here is the code:


***********************************************

<html>

<head>

<TITLE>Hope it works</TITLE>

</head>

<BODY bgcolor="#FFFFFF" text="#000000" link="#0000EE" vlink="#551A8B">

<script language="javascript">

<!--//

var channels = new Object();

channels['ANL'] = 15;

function param('channel')

var channel_num = channels[ param('channel') ];

if (channel_num == undefined)

alert("error: invalid channel");

else

window.location.href = channel_num + ".html";

//-->

</script>

<a href="http://americaspastime.tripod.com/trying/index.htm?channel=ANL">Works?</a>

</BODY>

</html>


***********************************************

If you can tell what is wrong, please help me. Your help will be greatly appreciated. Once I get this site done I will give you credit on my page. If you have a logo go ahead and put it in this forum

-Thank You
Copy linkTweet thisAlerts:
@JonaJun 19.2003 — [font=arial][color=maroon]Take out the apostrophes in function params([b]'[/b]channel[b]'[/b]){ ... [/color][/font]

[b]Jona[/b]
Copy linkTweet thisAlerts:
@chrismartzauthorJun 19.2003 — For some reason it still doesn't work. [URL=http://americaspastime.tripod.com/trying/]Here is the link to the page this is on.[/URL] I would really like to get this to work.
Copy linkTweet thisAlerts:
@Khalid_AliJun 19.2003 — [b]Moderators Node[/b]

Mulitple posts for same topic is considered extremely rude,it overloads the resources as well as moderators time to delete/move/merge threads.

Please be carefull.
Copy linkTweet thisAlerts:
@jeffmottJun 19.2003 — [size=2]channels[ANL] = 15;[/size]The ANL here [i]does[/i] require quotes.[size=2]channels[ param(channel) ][/size]You appear to be using the parameter parsing of the query string I provided, but I don't see where that code in the page. The channel inside param() here also needs to be quoted. The part that Jona was referring to is...[size=2]function param(channel){[/size]This is where the quotes needed to be removed, which you have done now. However, you have also given the function the same name as one for the parameter parsing routines. A more descriptive name might be something like change_channel[size=2]function change_channel(channel) {[/size]
Copy linkTweet thisAlerts:
@chrismartzauthorJun 19.2003 — Alright, I made all the modifications I could and it still doesn't seem to be working. I had the .js file being called in the head section and also the body section. I am beginning to become frustrated. If you can help please do. I believe my code is alright but am not sure if the .js file should just be on the page.
Copy linkTweet thisAlerts:
@chrismartzauthorJun 19.2003 — Also, am I supposed to modify the .js file that jeffmott created or just leave it alone.
Copy linkTweet thisAlerts:
@jeffmottJun 20.2003 — [b]Alright, I made all the modifications I could and it still doesn't seem to be working[/b][/quote]You have your change_channel function, but don't appear to invoke it anywhere.[b]Also, am I supposed to modify the .js file that jeffmott created or just leave it alone[/b][/quote]You can leave it alone.
Copy linkTweet thisAlerts:
@chrismartzauthorJun 20.2003 — what do you mean:[B]don't appear to invoke it anywhere[/B][/QUOTE] ????
Copy linkTweet thisAlerts:
@jeffmottJun 21.2003 — A function doesn't execute until you call (invoke) that function. You've defined the function, but never call it. Thus it is never executed.
Copy linkTweet thisAlerts:
@chrismartzauthorJun 21.2003 — okay, so would I put

<AHREF "http://americaspastime.tripod.com/trying/index.html?channel=ANL" onclick="change_channel()">Works?</a>
Copy linkTweet thisAlerts:
@JonaJun 21.2003 — [font=arial][color=maroon]No, you would call it onload (<body onload="change_channel();">), unless there is a specific time when you want to get the channel.[/color][/font]

[b]Jona[/b]
Copy linkTweet thisAlerts:
@chrismartzauthorJun 21.2003 — I would like to get in a link
Copy linkTweet thisAlerts:
@JonaJun 21.2003 — [font=arial][color=maroon]Do it however you like. If it doesn't work, try something else.[/color][/font]

[b]Jona[/b]
Copy linkTweet thisAlerts:
@chrismartzauthorJun 21.2003 — I know that, how would i call this in a link?
Copy linkTweet thisAlerts:
@JonaJun 21.2003 — [font=arial][color=maroon]The same way you said in your post above.[/color][/font]

[b]Jona[/b]
Copy linkTweet thisAlerts:
@chrismartzauthorJun 21.2003 — that way gives me the error from the else statement for some reason though. Have any other thoughts??
×

Success!

Help @chrismartz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...