Click to See Complete Forum and Search --> : Javascript, framesets, for and baffled
I have javascript in a frameset page, from which I call a div from my main frame using the code
parent.frames("main").document.getElementById(subnam).style.visibility="hidden";
where subnam is a variable, but this gives an error, can you see anything wrong with it? Its in a for function if that helps, interestingly if I put an alert box in the function, just returning subnam, then it doesn't return an error... :confused:
IxxI
Charles
05-28-2003, 06:35 AM
Try:
parent.frames["main"].document.getElementById(subnam).style.visibility="hidden";
or
parent.frames.main.document.getElementById(subnam).style.visibility="hidden";
No, tried those and I still get an error. Though it still works if I put an alert box in though...
IxxI
Please can anyone help - this is driving me crazy...:(
IxxI
How about zipping up the relavant files and uploading them, or posting a link...
khalidali63
05-28-2003, 09:43 AM
there are 2 possibilities.
parent.frames("main").document.getElementById(subnam).style.visibility="hidden";
in the above if the subname is a variable then its good otherwise thats wrong it should be
"subname"
second which I have experienced its stange but happens..
depending upon the number of frames you have in your frameset suppose 2
a left frame and a main frame
this is how you canaccess it and this works no matter what..
parent.frames[1].document.getElementById(subname)....
Right they'll need a bit of explaining as my coding leaves something to be desired...
If you look at edit.js then you'll see that there is a group of variables called sub1, sub2 etc. those show the numbers of sublinks that you should see from each menu item. If you open index.htm then after the alert boxes you should see that when the submenus come out they have that number of sublinks. If they have more than 4 then pressing the arrow will show them (yes I know the graphics are all the same and naff, but I had to shove something there). If now you go into menu.js and on line 92 (in the first for statement of function menuwidth) it should say alert(subnam);. If you take that out you'll see that the for statements fail and you get four or eight of twelve links shown (depending upon when the arrows disappear), why does this happen, and why does the alert box change it? I've tried swapping main.document for parent.main.document, parent.frames.main.document, parent.frames("main"). document, and parent.frames["main"].document, but to no avail. Any help would be much appreciated as I can make not head nor tail of it...
IxxI
EDIT: Sorry to all those with netscape, but the likelihood of it working at all on netscape is small, as I know nothing about it, and the menu has been done for a company who uses only IE. :eek:
khalidali63
05-28-2003, 10:06 AM
Originally posted by IxxI
..........I've tried swapping main.document for parent.main.document, parent.frames.main.document, parent.frames("main"). document, and parent.frames["main"].document, but to no avail.
IxxI
Try my suggestion above..
parent.frames[1].document.getElementById(subname)..
This will work...cus it always does..:-)
What is it supposed to be doing? It looks like it is working. I get 2 links for the first one, 3 for the second, 6 for the third, etc...? :confused:
Sorry Khalid, tried the parent.frames[1]. but that doesn't seem to make a difference either. I know that the syntax is correct because it works when I have an alert there, but I still get an error without. Also subnam is a variable, the script works fine when not in frames - its just I've had to modify it for frames, and thats when this problem started...
Thanks again,
IxxI
EDIT: pyro: even when you take the alert out of the code???
khalidali63
05-28-2003, 10:13 AM
I hate the code where people try to squeeze in allots of code without making it read able,I bet if alll of the above is working then its an if statement or a for loop after which some people try to ellude by not puttin the curly braces.....
let me see yoru code....if some one else doesn't figure it out by then
the codes all in testmenu.zip - further up. And I know my code is not particularly readable, but I'm only a newbie and this is my first big project, I'll make it more readable and comment it when it works - and yes I know I should do it as I go along, but I haven't quite got the hang of it yet. My for loops are all fine, though the problem does seem to be in the menuwidth function...
IxxI
Yes, for me, the code seems to be working fine (unless I don't understand the problem). I tried it in IE6.
khalidali63
05-28-2003, 10:28 AM
Ok here it goes..
When I first loaded I got error in IE
after my favourite changes in the code
I am not getting any errors any more,now problem as pyro said ,what is the problem in the code...lol
http://68.145.35.86/temp/IxxI/testmenu/index.htm
I'm using IE 6 too, with Win XP Pro (if that makes a difference), and so when you go to line 92 of menu.js and remove the line that says "alert(subnam);", and then refresh index.htm, you still get 2 sublinks in the first link, 3 in the 2nd etc.
The only reason I'm checking quite so carefully is with all 3 computers I've tried it on today if I remove that line I get 4 links in the first, 4 in the second and 8 in the third...
Thanks,
IxxI
Try this... No alert, working fine for me.
Distressingly for me - same problem...
Any ideas??
IxxI
EDIT: I've tried on a 98 computer running IE5.5 and I still get the same problem. Aargh.:mad:
khalidali63
05-28-2003, 10:46 AM
This is what I get in the menu.
with or without alert at line 92 in menu.js
1. Production ---> Production
--->dRopdown
--->dRopdown
2. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
3. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
4. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
5. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
6. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
7. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
8. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
9. Production ---> Production
--->dRopdown
I get the above with or without an alert at line 92....did I miss something????
Yeah, most of those with four dropdowns (the 3rd, 4th, 5th, 6th, 7th, and 8th to be more precise), you should be able to click the down arrow and make it more (should appear to the right of the dropdowns). And I've now tried on four different machines, and without the alert I get four for the first, four for the second etc. and the error on page symbol in the bottom left. I can't work out what's going on...
IxxI
Yeah, I think you missed the little arrows saying there were more... ;) This is what I get:
1. Production ---> Production
--->dRopdown
--->dRopdown
2. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
3. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
4. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
5. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
6. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
7. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
8. Production ---> Production
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
--->dRopdown
9. Production ---> Production
--->dRopdown
I've got to run, but for Khalid, if he has the time to look at it more, I've found a way to simulate the problem. Try clicking the top Production link... Now I get the menu all screwed up...
I think I'm gonna cry *sob*. Four computers and all give me 4, 4, 8, 8, 8, 12, 12, 12, 4 with no alert.
IxxI
khalidali63
05-28-2003, 11:03 AM
What pyro just is that your problem that the first one shows 2 links but when clicked on it it shows 4 links?
4, 4, 8, 8, 8, 12, 12, 12, 4
if above is incorrect how many do you expect for each level above...
god I am having so much hard time comprehending this darn problem
lol
No, if you go to main.htm and put in body onload="parent.menuwidth()" it might sort it, but my problem is that if I load it without the alert in at line 92 I get 4, 4, 8, 8, 8, 12, 12, 12, 4, EVEN BEFORE I'VE CLICKED THE FIRST LINK whereas I should be getting the numbers that are in edit.js where it says:
//Put the number of sublinks in here for each menu item. If you set this to 0 the page will not work - to have no submenu for a certain link enter 0 in the boxes above.
var sub1=2
var sub2=3
var sub3=6
var sub4=7
var sub5=5
var sub6=9
var sub7=10
var sub8=11
var sub9=1
which in this case is 2, 3, 6, 7, 5, 9, 10, 11, 1. I've got to go home now, but I'll be back on in an hour or so. I really do appreciate this Khalid and pyro, and I'm sorry if I haven't been clear, its just driving me mad...
Thanks again,
IxxI
I've found the problem, its windows script 5.6. Which is maddening, because all their computers have it on, and microsoft knowledgebase has nothing on the problem. Damnit. Thanks for all your help, both...
IxxI