#1 (permalink)  
Old 05-09-2007, 01:24 AM
Registered User
 
Join Date: May 2007
Posts: 3
Question javascript: html page array with an iframe

I read an earlier post about paging through some html pages using an array in javascript, but I was unable to find the post again. However, this is what I have:
Code:
<script type="text/javascript">
var x = 0;
var midpage = new Array("adtable.html", "nothing.html", "nothing.html");
function changePage()
{
	var y = "";
	document.getElementById('adtable') = y;
	if (x==2)
	{
		x = 0;
	} else {
		x = x + 1;
	}
	y.src = midpage[x];
}
</script>
and then my IFrame:
Code:
<iframe id="adtable" name="adtable" src="adtable.html" height=202 align="center" width="100%" marginheight=0 marginwidth=0 scrolling="no" frameborder=0>
NO WORKY!!!
</iframe>
When I click one of these buttons:
HTML Code:
<a class="inline-button" onClick="changePage()">Right</a>
Nothing happens.
By the way, I am testing this in the newest version of Firefox.
Any help is appriciated, sorry if this is double post.
Reply With Quote

  #2 (permalink)  
Old 05-09-2007, 12:45 PM
Deadeye's Avatar
Moderator
 
Join Date: Aug 2005
Location: San Diego, CA
Posts: 274
Send a message via MSN to Deadeye
do you have a link that I can see the current code in action? It would really help to help solve the problem.

Also, what is the point of that if statement in the JS code?

Wesley
Reply With Quote
  #3 (permalink)  
Old 05-10-2007, 12:53 AM
Registered User
 
Join Date: May 2007
Posts: 3
I don't have the code live. I'm just testing it on a localhost server. But the point of the if statement is so that when you are cycling through the array the x used will not cause the array to go out of bounds.
Reply With Quote
  #4 (permalink)  
Old 05-10-2007, 08:11 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
I think you have this statement written backwards:
Code:
document.getElementById('adtable') = y;
I believe it should be:
Code:
y = document.getElementById('adtable');
Also, rather than performing the if statement the way you have it, try doing it this way instead:

Code:
	if (x>=midpage.length)
	{
		x = 0;
	} else {
		x = x + 1;
	}
	y.src = midpage[x];
That should mean that you don't have to physically count the number of the items in your midpage array. Just be sure to leave it as ">=" as opposed to just ">", as your array "length" is always going to be 1 number greater than your highest index (being that the "length" is an actual count of the items in the array, and your indexes are zero-based).
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #5 (permalink)  
Old 05-10-2007, 06:50 PM
Registered User
 
Join Date: May 2007
Posts: 3
Ah yes ">=". Thanks for the help, I'll try it out. Though I was coding a smaller version the other day. Something like this
Code:
// js file
//array
var midpage = new Array();
midpage[0] = "Show";
midpage[1] = "Me";
midpage[2] = "The";
midpage[3] = "Money";
//globals
var x = 0;
var box = getElementByID('testbox');
function changeWord()
{
  if (x==3)
  {
    x = 0;
    box.value = midpage[x];
  } else {
    box.value = midpage[x];
    x++;
  }
}
And then I had a button (that worked when I put an alert() into the onclick) that would do changeWord() onclick and a textbox input with the id and name of testbox, but the function for some reason still wouldn't work. I can't figure it out.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash loads html, html (into flash) links to another html inside flash, or to a popup kenny_gr Graphics and Flash 1 10-16-2007 09:32 AM
javascript for redirecting iFrame page gilgalbiblewhee Programming and Scripting 0 08-29-2006 02:36 PM
"session validation checking" in html page ...HELP dragon Programming and Scripting 4 08-15-2006 02:06 PM
HTML Code: Centering Page kobedog84 Programming and Scripting 4 08-11-2006 01:35 PM
controling load order of swfs and jpgs on an html page, maybe javascript? NaradaVantari Graphics and Flash 3 04-28-2005 08:42 PM


All times are GMT -5. The time now is 02:30 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter