Forum Moderators: open

Message Too Old, No Replies

passing in a integer into a file to be read

         

sarsonuk

3:44 am on Mar 27, 2004 (gmt 0)

10+ Year Member



I am trying to control a script by setting an integer when loading the webpage i.e

"javascript:parent.mainFrame.location.href='./america_ss.html?frame=3'"

I set the function by

onfiltered="javacript:SetSlide(<%=Request.QueryString['frame']%>)"

Opening the page works fine but setting the javacript function doesn't seem to be working

Does anyone have any suggestions

Pete

Rambo Tribble

5:27 am on Mar 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the JavaScript part of an ASP page? If so, perhaps the ASP folks could shed more light on this. I don't believe onfiltered is an HTML event or standard JavaScript object property, per se.

sarsonuk

5:32 am on Mar 27, 2004 (gmt 0)

10+ Year Member



No I'm just using a standard javascript/html file.
Do you know how I would append this to an existing onload event?
I currently have this in the onload onload="javascript:{if(parent.frames[0]&&parent.frames['menuFrame'].Go)parent.frames['menuFrame'].Go()}">

Thnaks
Pete

Rambo Tribble

5:54 am on Mar 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just for ease of maintenance, you might want to consider moving this code into a function in the head of your document. The structure is like:
<script type="text/javascript>
function myFunc(){
//your existing code
}
</script>

You then call it with:
onload="myFunc();"

JavaScript statements are separated with semicolons, so if you want to put multiple statements in a line just put semicolons between them. This is how you can append your existing onload, but I don't think that will solve your problems.

The reason I thought you were using ASP is that post data (the data in the URL after the "?") is only normally handled by server-side scripts. Unless you parsed the data out with string parsing functions, JavaScript doesn't see this.

Also, the <% and %> is the way server-side scripts are embedded in a page; they have little meaning in JavaScript, except that they are greater-than (>), less-than (<) and modulo operators, which I doubt you want to use here.

I guess I'm still not clear what the JavaScript function SetSlide() is supposed to do, but the code should probably be in the head of the document, like the example above, and be called by the onload as in:
onload="myFunc();SetSlide();"
A variable can be sent to SetSlide by placing it between the parentheses, but you'll need to handle it at the function's execution end to pass it to the body of the function.

If this seems confusing, you may need to back up and study JavaScript functions, or maybe ask more specific questions. Seeing a little more of your code wouldn't hurt, either. I think where you have menuFrames in single quotes within square brackets, we need to re-evaluate what you're trying to do and where the variable is coming from. At first wash, the code you are asking about appending doesn't look functional.

sarsonuk

6:29 am on Mar 27, 2004 (gmt 0)

10+ Year Member



Okay you seem to be a demi god,

I have this code that I went route we were talking about that does what you said but I couldn't get it to function correctly, Could you point me to the place where I am going wrong

I have this coded to link to a page then execute the onload with setslide which by the way is selecting a slideshow to play

javascript:parent.mainFrame.location.href='./america_ss.html';parent.mainFrame.onload=function(){parent.mainFrame.setslide(3)}

This loads the page okay but doesnt execute the script

Do you know if I need to add anything to the called page(america_ss.html) for this to work?

Pete

Rambo Tribble

2:15 pm on Mar 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I may be old enough to be god, but there's no direct relation.

I guessing a bit here, but it looks like you want to load the slideshow file in a frame, named mainFrame, then execute the slideshow code. One thing it would be helpful to know, is the slideshow code JavaScript?

If the slideshow is JS, it will probably work best to put the code in a .js file and link to it from america_ss.html. Then the onload handler can be put in body tag of that file and call the function when the file has loaded.

A .js file is a straight text file with just your JavaScript code in it; no tags, headers, or anything else, just code. If you called it myFuncs.js, you would link to it from the HTML file with this in the head of HTML file:
<script type="text/javascript" src="myFuncs.js"></script>

If your function to run the slideshow is called startSlide, you'd call it from the body tag like this:
<body onload="startSlide();">

If you need to pass an integer to the slideshow function, your tag would look something like this:
<body onload="startSlide(3);">

All of this depends, of course, on what your slideshow code looks like.

Does that make sense? Better yet, does that give you an idea of how to proceed?

sarsonuk

4:31 pm on Mar 27, 2004 (gmt 0)

10+ Year Member



Rambo,
What you just described is exactly what I have done in one way or another.
The problem I'm having is passing a integer into the slideshow function to control which slideshow I want to show. The slideshow code is javascript.
I would ideally like to have a link in a menu that says goto_link.execute_code which I have tried in the following ways

parent.frame.location=href...;parent.frame.function(num) -- This didn't work and I put it down to the fact the file hadn't loaded fully before the function executed. The page loads fine though.

I tried something someone suggested i.e. trying to set the onload function from the menu item that calls the file i.e. javascript:parent.mainFrame.location.href='./america_ss.html';parent.mainFrame.onload=function(){parent.mainFrame.setslide(3);return false} but this had the same result as the above that the page loaded but the script didn't do what I expected.

Then I tried putting a? into the location handler i.e href='./america_ss.html?3' but from what I learnt I don't think this can work and when I tried it I got the same effect as the other that the page loaded but the script didn't execute.

I have some links in the file I'm loading so that I can execute the script indepently which works fine.

If you go to my page at www.geocities.com/sarsonuk/travel.html then select america/sugarloaf you see what i'm talking about

Can you see what I'm trying to achieve?

I basiscally have a javascript that has a multitude of imgs stored in a multiindex array and by setting an input integer into the function setslide(num) dictates which element of the array is used for the slideshow,

Thanks for all your help
The unworthy one

Rambo Tribble

5:44 pm on Mar 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm in a big rush to get to work, so I'll have to respond more fully this evening, but the onload event is, to the best of my knowledge, intrinsic to the page being loaded. I don't think you can read it externally.

Rambo Tribble

2:01 am on Mar 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I went to your URL and I think I see what you want. Let me try to describe it: A user clicks on an item in the drop-down list and a slide show loads and starts in the main content frame, replacing the original content (which has a smaller slideshow, upper left).

It appears there should be two images in the Sugarloaf show, perhaps more. I'm not completely sure that the problems with the show are with the script starting before the images load, but if the images are being loaded as objects into the array (as opposed to just URL's being loaded), that's a strong possibility.

If the images are being loaded as objects into an array, I'm pretty sure onload cannot be made to do the job you need. You see, being loaded into an array doesn't really make the images part of the document. At least not a part that onload tests for, because they don't belong to the body.

I see a couple possibilities. One approach would be to load the images (other than the first which would be visible) into hidden divs in the body of the page that is loaded into the frame. Then the onload will work and can trigger a script that uses getElementById to cycle the divs in and out of visibility. Again, to avoid all the parent/child notation hassle, I'd just put the script in an external .js file and link to it. I think this could simplify your pages, but would require reengineering them.

To get your present system to work, I think you'll have to develop a while() loop that cycles through the image array as it loads. The loop would test the array for any elements that are undefined and continue to loop if one is found, quitting the loop if none is found, then allowing or calling the slideshow code to execute.

How does that sound?

sarsonuk

6:12 am on Mar 28, 2004 (gmt 0)

10+ Year Member


Rambo,
What you said sounds great, I already have a .js defined which I have included at the bottom of the reply. You can see from this that I have the images setup as just URLs at the moment, I intend to do what I did with the travel page and load them into cach memory so as to reduce bandwidth usage once I get over this hurdle.

So from what you said because I have the .js file I can imbed the images into the file and select which div from the onload process with a calling string?
I see that from this that I would have to move some of the script to the html file so that the images could be imbeded into the body of the document i.e. preloading them.
Can you explain how I would do this with the div as it something I have seen a great deal of but have no idea about!
I agree that if something should be done then it should be done properly so I'll re-engineer my files and will proberly learn a great deal.
Thanks for your time and help,

------------------------------------------------------
america_ss.html
------------------------------------------------------
<HTML>
<Head>
<title>Slideshow</title>
<script language="JavaScript1.2" type='text/javascript' src='slideshow.js'>

</script>
</Head>
<BODY bgcolor="#000000" text="#FFFFFF" onload="if(parent.frames[0]&&parent.frames['menuFrame'].Go)parent.frames['menuFrame'].Go()">
<table width="646" align="center">
<!--DWLayoutTable-->
<tr>
<td width="640" height="640" align="center" valign="top">
<script>
if (linked)
document.write('<a href="javascript:clickredir()"><img src="'+slideshows[0][0]+'" name="multislide" border=0></a>')
else
document.write('<img src="'+slideshows[0][0]+'" name="multislide">')
</script>
</td>
</tr>
</table>
<p align="center">
<!-- debug code -->
- <a href="javascript:setslide(0)">SugarLoaf Maine 2002-2004</a><br>
- <a href="javascript:setslide(1)">Niagra Falls USA Feb 2004</a><br>
- <a href="javascript:setslide(2)">Philadelphia PA USA Feb 2004</a><br>
- <a href="javascript:setslide(3)">Dallas TX USA Nov 2003</a><br>
- <a href="javascript:setslide(4)">California USA Feb 2002</a><br>
- <a href="javascript:setslide(5)">Providence RI USA Feb 2002</a><br>
- <a href="javascript:setslide(6)">Plymouth MA USA Feb 2002</a><br>
- <a href="javascript:setslide(7)">Boston MA USA 2000-2001</a><br>
- <a href="javascript:setslide(8)">White Mountains Nh USA Oct 2001</a><br>
- <a href="javascript:setslide(9)">New York NY USA Apr 2001</a><br>
</p>
</BODY>
</HTML>
-----------------------------------------------------
slideshow.js file
-----------------------------------------------------
//#1 SPECIFY number of slideshows
var number_of_slideshows=10

//#2 SPECIFY interval between slide (2000=2 seconds)
var interval=2000

//#3 SHOULD each slide be linked to a unique URL?
var linked=1

var slideshows=new Array(number_of_slideshows)
for (i=0; i <number_of_slideshows; i++)
slideshows[i]=new Array()

//#4 SPECIFY image paths of 1st slideshow
slideshows[0][0]='../america/sugarloaf/sugarloaf00.jpg'
slideshows[0][1]='../america/sugarloaf/sugarloaf01.jpg'
slideshows[0][2]='../america/sugarloaf/sugarloaf02.jpg'
slideshows[0][3]='../america/sugarloaf/sugarloaf03.jpg'
slideshows[0][4]='../america/sugarloaf/sugarloaf04.jpg'
slideshows[0][5]='../america/sugarloaf/sugarloaf05.jpg'
slideshows[0][6]='../america/sugarloaf/sugarloaf06.jpg'
slideshows[0][7]='../america/sugarloaf/sugarloaf07.jpg'
slideshows[0][8]='../america/sugarloaf/sugarloaf08.jpg'
//SPECIFY image paths of 2nd slideshow (remove if number_of_slides less than 2)
slideshows[1][0]='../america/Niagra/Niagra01.jpg'
slideshows[1][1]='../america/Niagra/Niagra02.jpg'
slideshows[1][2]='../america/Niagra/Niagra03.jpg'
slideshows[1][3]='../america/Niagra/Niagra04.jpg'
slideshows[1][4]='../america/Niagra/Niagra05.jpg'
slideshows[1][5]='../america/Niagra/Niagra06.jpg'
slideshows[1][6]='../america/Niagra/Niagra07.jpg'

//SPECIFY image paths of 3rd slideshow (remove if number_of_slides less than 3)
slideshows[2][0]='../america/Philadelphia/Philadelphia01.jpg'
slideshows[2][1]='../america/Philadelphia/Philadelphia02.jpg'
slideshows[2][2]='../america/Philadelphia/Philadelphia03.jpg'
slideshows[2][3]='../america/Philadelphia/Philadelphia04.jpg'
slideshows[2][4]='../america/Philadelphia/Philadelphia05.jpg'
slideshows[2][5]='../america/Philadelphia/Philadelphia06.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[3][0]='../america/Dallas/Dallas01.jpg'
slideshows[3][1]='../america/Dallas/Dallas03.jpg'
slideshows[3][2]='../america/Dallas/Dallas04.jpg'
slideshows[3][3]='../america/Dallas/Dallas05.jpg'
slideshows[3][4]='../america/Dallas/Dallas06.jpg'
slideshows[3][5]='../america/Dallas/Dallas07.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[4][0]='../america/california/california01.jpg'
slideshows[4][1]='../america/california/california02.jpg'
slideshows[4][2]='../america/california/california03.jpg'
slideshows[4][3]='../america/california/california04.jpg'
slideshows[4][4]='../america/california/california05.jpg'
slideshows[4][5]='../america/california/california06.jpg'
slideshows[4][6]='../america/california/california07.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[5][0]='../america/providence/providence01.jpg'
slideshows[5][1]='../america/providence/providence02.jpg'
slideshows[5][2]='../america/providence/providence03.jpg'
slideshows[5][3]='../america/providence/providence04.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[6][0]='../america/plymouth/plymouth01.jpg'
slideshows[6][1]='../america/plymouth/plymouth02.jpg'
slideshows[6][2]='../america/plymouth/plymouth03.jpg'
slideshows[6][3]='../america/plymouth/plymouth04.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[7][0]='../america/boston/boston01.jpg'
slideshows[7][1]='../america/boston/boston10.jpg'
slideshows[7][2]='../america/boston/boston11.jpg'
slideshows[7][3]='../america/boston/boston14.jpg'
slideshows[7][4]='../america/boston/Boston04.jpg'
slideshows[7][5]='../america/boston/Boston05.jpg'
slideshows[7][6]='../america/boston/Boston07.jpg'
slideshows[7][7]='../america/boston/Boston08.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[8][0]='../america/white_mountains/newhamp01.jpg'
slideshows[8][1]='../america/white_mountains/newhamp07.jpg'
slideshows[8][2]='../america/white_mountains/newhamp10.jpg'
slideshows[8][3]='../america/white_mountains/newhamp13.jpg'
slideshows[8][4]='../america/white_mountains/newhamp14.jpg'
slideshows[8][5]='../america/white_mountains/newhamp15.jpg'

//EXTEND THIS ARRAY if more than 3 slide shows

slideshows[9][0]='../america/NewYork/centralpark.jpg'
slideshows[9][1]='../america/NewYork/empirestate.jpg'
slideshows[9][2]='../america/NewYork/lib.jpg'
slideshows[9][3]='../america/NewYork/neon.jpg'
slideshows[9][4]='../america/NewYork/skyline.jpg'
slideshows[9][5]='../america/NewYork/statu_1.jpg'
slideshows[9][6]='../america/NewYork/view.jpg'

<!--Remove the below portion if "var linked" above is set to 0-->

var slidelinks=new Array(number_of_slideshows)
for (i=0; i <number_of_slideshows; i++)
slidelinks[i]=new Array()

//#5 SPECIFY urls of 1st slideshow
for (i=0; i< 9; i++)
slidelinks[0][i]='../america/sugarloaf/sugarloaf.html'

//SPECIFY urls of 2nd slideshow (remove if number_of_slides=1)
for (i=0; i< 6; i++)
slidelinks[1][i]='../america/Niagra/niagra.html'

//SPECIFY urls of 3rd slideshow (remove if number_of_slides less than 3)
for (i=0; i< 5; i++)
slidelinks[2][i]='../america/Philadelphia/Philadelphia.html'

//SPECIFY urls of 3rd slideshow (remove if number_of_slides less than 3)
for (i=0; i< 5; i++)
slidelinks[3][i]='../america/Dallas/dallas.html'

//SPECIFY urls of 3rd slideshow (remove if number_of_slides less than 3)
for (i=0; i< 6; i++)
slidelinks[4][i]='../america/california/california.html'

//SPECIFY urls of 3rd slideshow (remove if number_of_slides less than 3)
for (i=0; i< 4; i++)
slidelinks[5][i]='../america/providence/providence.html'

//SPECIFY urls of 3rd slideshow (remove if number_of_slides less than 3)
for (i=0; i< 4; i++)
slidelinks[6][i]='../america/plymouth/plymouth.html'

//SPECIFY urls of 3rd slideshow (remove if number_of_slides less than 3)
for (i=0; i< 7; i++)
slidelinks[7][i]='../america/boston/boston.html'

for (i=0; i< 5; i++)
slidelinks[8][i]='../america/white_mountains/white_mountains.html'

for (i=0; i< 6; i++)
slidelinks[9][i]='../america/NewYork/ny.html'

function clickredir(){
window.location=slidelinks[maininc][subinc]
}

<!-- END removal ---------------------------------->

var maininc=0
var subinc=0

function slideit(){
subinc= (subinc<slideshows[maininc].length-1)? subinc+1: 0
document.images.multislide.src=slideshows[maininc][subinc]
}

function setslide(which){
clearInterval(runit)
maininc=which
subinc=0
runit=setInterval("slideit()",interval)
}
runit=setInterval("slideit()",interval)

Rambo Tribble

8:41 pm on Mar 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I whipped this together, give it a try:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Slideshow w/Divs</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body{
height:100%;
width:100%;
background:#000;
}
div#main{
height:100%;
width:100%;
margin:0;
padding:0;
}
.ss{
position:absolute;
margin:10% 0 0 20%;
visibility:hidden;
}
.v{
visibility:visible;
}
-->
</style>
<script type="text/javascript">
<!--
var rep_ct=0;
var num_slds=0;
var sldArr=new Array();
var setReps;
function setSlides(sld_num){
num_slds=sld_num;
for (var i=0;i<sld_num;i++){
var d_no=i+1;
sldArr[i]="d" + d_no;
}
setReps=window.setInterval("showSlides()",2000);
}
function showSlides(){
if(rep_ct==num_slds){
rep_ct=0;
}
var sw1=document.getElementById(sldArr[rep_ct]);
if(rep_ct<num_slds-1){
var sw2=document.getElementById(sldArr[++rep_ct]);
}else{
sw2=document.getElementById(sldArr[0]);
++rep_ct;
}
sw1.style.visibility="hidden";
sw2.style.visibility="visible";
}
//-->
</script>
</head>
<body onload="setSlides(4);" onunload="window.clearInterval(setReps);">
<div id="main">
<div id="d1" class="ss v"><img src="yourPic1.jpg" alt="" /></div>
<div id="d2" class="ss"><img src="yourPic2.jpg" alt="" /></div>
<div id="d3" class="ss"><img src="yourPic3.jpg" alt="" /></div>
<div id="d4" class="ss"><img src="yourPic4.jpg" alt="" /></div>
</div>
</body>
</html>

Note that you need to pass the number of divs to the setSlides() function when called by onload and that you need to keep the div id convention of d1, d2, etc. All the JavaScript, can, of course, be placed in a separate .js file and linked to by the various HTML files that use the code. The same is true for the style sheet information, using a .css file. The result can be very compact HTML files.

Purple Martin

1:25 am on Mar 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I once wrote a script that parses any search string and automatically declares all search parameters as JavaScript variables with values. It handles both numeric and string variable types correctly. Just paste it into a script tag at the top of the head of the document.

You could use this as an easy way to access the value directly in JavaScript without having to think about server-side tags.

if (location.search.length > 0) {
launchString = location.search.substring(1, location.search.length);
var launchStringArray = launchString.split("&");
for (var i = 0; i <= launchStringArray.length - 1; i++) { var left = launchStringArray[i].substring(0, launchStringArray[i].indexOf("="));
var right = launchStringArray[i].substring(launchStringArray[i].indexOf("=") + 1, launchString.length);
if (isNaN(right)) {
right = '"' + right + '"';
}
eval("var " + left + " = " + right);
}
}

sarsonuk

1:54 am on Mar 29, 2004 (gmt 0)

10+ Year Member



Where is the string coming from?
I really want to do something like this

make href = [website.com...]

then parse this number into a javascript function in the head of the document like

<head>
<script>
function(var>
</script>
</head>

I am a very basic website programmer and I have found out that I nothing when it comes to this stuff and the guys like rambo that have been responding to my questions have taught me a great deal in the last few days.

I am in the process of moving my site so that I can use a asp page to process the above so that it makes what I want to do very simple as the website I have at the moment doesn't allow it.

If this does this in the same simplistic manner then I would love to adopt your method

Rambo Tribble

11:36 pm on Mar 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sarsonuk,

Was the file I outlined above clear? With that simple code you could replace what you already have, with probably less work than getting your current system to work.

To try it just cut and paste the code into your editor, put real image names in the image tages, and give it a run. If it looks good, I can tell you more about separating the JS and CSS from the HTML and help you with getting it positioned correctly for your needs.

Purple Martin

8:20 am on Mar 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I really want to do something like this
make href = [website.com...]

then parse this number into a javascript function in the head of the document like

<head>
<script>
function(var>
</script>
</head>


OK. Let's assume the url is this:
[website.com...]

Firstly, add my code at the top of the script tag.

Secondly, define a function:
myFunction(arg) {
arg = "The value in the url is " + arg
alert(arg)
}

Thirdly, call your function just like you want to:
myFunction(fruit)

Rambo Tribble

1:38 pm on Mar 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PurpleMartin,

Actually, sarsonuk's problems extend beyond passing and parsing a character string. His slide show isn't working, as least in part, because he is creating an array of URL's, not image objects.

The links in question are used to load his own file into a frame on his document that is resident on the browser at the time of the call. As a result, the pass/parse functionality isn't benefitting the process, just adding complexity.

I think what will serve sarsonuk best is to scrap his current, overly complex approach, and develop a simpler system that is easier for him to maintain.