Click to See Complete Forum and Search --> : can't get this right
chrismartz
06-19-2003, 09:16 AM
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 http://americaspastime.tripod.com/trying/ (website) is here.
-Thanks
Khalid Ali
06-19-2003, 09:20 AM
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...
chrismartz
06-19-2003, 03:02 PM
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
Take out the apostrophes in function params('channel'){ ...
Jona
chrismartz
06-19-2003, 03:25 PM
For some reason it still doesn't work. Here is the link to the page this is on. (http://americaspastime.tripod.com/trying/) I would really like to get this to work.
Khalid Ali
06-19-2003, 03:43 PM
Moderators Node
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.
jeffmott
06-19-2003, 03:54 PM
channels[ANL] = 15;The ANL here does require quotes.channels[ param(channel) ]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...function param(channel){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_channelfunction change_channel(channel) {
chrismartz
06-19-2003, 06:05 PM
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.
chrismartz
06-19-2003, 06:06 PM
Also, am I supposed to modify the .js file that jeffmott created or just leave it alone.
jeffmott
06-19-2003, 08:02 PM
Alright, I made all the modifications I could and it still doesn't seem to be workingYou have your change_channel function, but don't appear to invoke it anywhere.Also, am I supposed to modify the .js file that jeffmott created or just leave it aloneYou can leave it alone.
chrismartz
06-20-2003, 07:57 AM
what do you mean:don't appear to invoke it anywhere ????
jeffmott
06-20-2003, 08:32 PM
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.
chrismartz
06-20-2003, 08:35 PM
okay, so would I put
<AHREF "http://americaspastime.tripod.com/trying/index.html?channel=ANL" onclick="change_channel()">Works?</a>
No, you would call it onload (<body onload="change_channel();">), unless there is a specific time when you want to get the channel.
Jona
chrismartz
06-20-2003, 08:49 PM
I would like to get in a link
Do it however you like. If it doesn't work, try something else.
Jona
chrismartz
06-20-2003, 08:55 PM
I know that, how would i call this in a link?
The same way you said in your post above.
Jona
chrismartz
06-21-2003, 10:02 AM
that way gives me the error from the else statement for some reason though. Have any other thoughts??