i have created a page which has an iframe held on it i now what to post the data from this iframe and make it available to my other php page. I have researched this a bit and found out it can be done using javascript. the code i have found is this.

<script type="text/javascript">
document.getElementsByName('rand')[0].value = document.getElementsByName('main')[0].src;
</script>

i am not to up on javascript so a little help is needed with this. i know the first element is the name of the hidden input i want to post, were i loose understanding is the next element name. is this the name of the page that the information needs to be posted to or is this how it posts it to the page the iframe is held on (main being the name used for that).

from my research i think i am beginning to understand this code a bit more but if someone knows if i am wrong please tell me.

as it is asking for the element by name then the number in the [] is not needed as this is the elements id number in the array. So as i have put the name rand in it will already know which element i want to post.

the next part is what i am still struggling to understand. It has the =value section and this is where i am stuck. the value in this section i think must have something to do with where the information is being posted to but as the the page were i found this code did not explain things to greatly i am lost.

please someone explain this code to me or point me in the right direction of were to find a good example and explanation of the code so i can then try to implement the code on to my site.

i have used a different solution now, still not got that working fully yet.

if someone could send me a link with a good explanation of the above code though that would be great as it is always nice to know how things work when you aint seen them before.

<script type="text/javascript">
document.getElementsByName('rand')[0].value = document.getElementsByName('main')[0].src;
</script>

The function getElementsByName returns a nodelist i.e. an array of all the elements which go by that name. Hence the array indexing operator [] is a must. If you are pretty sure that there is only one element on the entire page which goes by that name, you can do document.getElementsByName('name')[0] . The first line probably sets the value of some form element e.g. an input element and the second line probably sets the source of the iframe element which goes by the name of 'main' .

This question has already been answered. Start a new discussion instead.