Forum Moderators: open

Message Too Old, No Replies

Function doesn't work (partially)

         

alexey9

7:20 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



Hello guys,

I'm new to JS. I have a page with few javascript functions and some of these functions do not work. But some of lines in called function work.

For example, I have function:

function startScript()
{
document.getElementById('waitImage').src='$photoUploadedUrl';
document.photoSubmit.reset();
window.parent.document.getElementById('photoFrame').location = 'http://www.example.com';
document.write('ok');
}

I call this function by this:

window.onload = startScript();

First two lines of this code work, but other two do not work. I've checked syntax a lot of times and it seems ok to me.

I also have another functions that have same problem.

I'm totally confused with JS. I never met with such strange problems in other languages.

I wonder did I miss something or it's JS's bug?

mehh

8:51 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



seeing as you have a few functions like this here are two tips on bug hunting in JS:

use alert() alot if your code isn't working it will help you track down a malfunctioning line.

and seeing as your code dosn't work from line 3 on it suggests line 3 is wrong.

Here I think that window.parent. I think it should be parent.window.
I think that the code in this case can be shortened to:


function startScript()
{
document.getElementById('waitImage').src='$photoUploadedUrl';
document.photoSubmit.reset();
parent.getElementById('photoFrame').location = 'http://www.example.com';
alert('ok');
}

Note: I have said I think a lot here because my knowlage on the window object is sketchy at best

alexey9

8:11 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



Thanks for reply.

I changed code, but still it doesn't work. :(

Drag_Racer

12:25 am on Aug 11, 2007 (gmt 0)

10+ Year Member



I am guessing 'photoFrame' is an iframe?

if so try

parent.getElementById('photoFrame').src = 'http://www.example.com';

also, if this javascript snippit is in the framed page code, then this document and the parent document must be from the same domain or a permission denied error may be generated

alexey9

7:33 pm on Aug 12, 2007 (gmt 0)

10+ Year Member



I've just tried code, but it didn't resfresh an iframe.

I put this code:
parent.getElementById('photoFrame').src = 'http://www.example.com';

into another iframe, but it didn't work. Also, I get JS error:
parent.getElementById is not a function.