PDA

View Full Version : (Javascript) I cannot access an element from an iFrame that is on the main page.


msimmons
09-06-2002, 04:10 PM
I am running some code in an iframe that alters elements on the page that the iframe is on. I can alter one (a div) but cannot alter the other (an imput). Any ideas?

<script language="javascript">
if (window.parent.reservationReservationID){
alert('found it');
}else{
alert('did not find it');
}

with (window.parent){

reservationfind.style.background='yellow';
}
</script>

as you can tell from the above code I am just testing to see if the imput is there (it is... I have triple checked). I keep getting the alert 'did not find it'. I am able to change the color of the other item though.

Michael

beetle
09-06-2002, 04:33 PM
Is your input in a form? if yes, then your reference is invalid. If no, then your reference is valid for IE only. Instead, use one of these:

parent.getElementById('reservationReservationID')

or

parent.formName.reservationReservationID

or

parent.formName.elements['reservationReservationID']

msimmons
09-06-2002, 04:36 PM
Originally posted by beetle
Is your input in a form? if yes, then your reference is invalid. If no, then your reference is valid for IE only. Instead, use one of these:

parent.getElementById('reservationReservationID')

or

parent.formName.reservationReservationID

or

parent.formName.elements['reservationReservationID']
I hadden't received the email notification yet of your post but was comming back to reply that I found it :)

You are correct, it is in a form and i used:
window.parent.formName.reservationReservationID

I tried:
parent.getElementById('reservationReservationID')

before posting but received:
Object doesn't support property or method.

Thanks,
Michael

beetle
09-06-2002, 04:48 PM
Sorry, should be

parent.document.getElementById('reservationReservationID')

msimmons
09-06-2002, 04:57 PM
Cool it worked :)
That is more up to standards right?

Michael

beetle
09-06-2002, 05:11 PM
Yes, definitely, although referencing an object via it's form is perfectly valid. I prefer to use the elements collection when doing so.

msimmons
09-06-2002, 05:13 PM
Same here... even though I perfer to use IE and develop under it I try to stay as close to the standards as I can.
Thanks again,
Micahel

beetle
09-06-2002, 05:15 PM
Originally posted by msimmons
even though I perfer to use IE and develop under it Uh oh, you better hope jkd didn't hear you say that! :D

Just kidding jkd :p

msimmons
09-06-2002, 05:17 PM
I almost didn't post that for fear of being flamed ;)
Michael