<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'
.