views:

17

answers:

1

I have javascript, which is in iframe. When i check radio button in iframe, on parent window change value. It working perfect on firefox, but not on IE... Can someone help me with this problem?

<script type="text/javascript">
function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function asd(){
var qwer =  getCheckedValue(document.forms['uas'].elements['icon']);
window.parent.document.forms['register'].lang.value = qwer;
window.parent.document.getElementById("images").getElementsByTagName("img")[0].src = "images/lang/" + qwer  + ".png";

}
</script>

<form name="uas" method="GET" action="" onchange="asd();">
<label id="1"><input type="radio" name="icon" value="1">One</label><br><label id="2"><input type="radio" name="icon" value="2">Two ...
A: 

The problem with your code is the onchange event attached to the form element, IE does not support this. Instead, you have to use onchange event for each of the radio buttons:

<label id="1"><input type="radio" name="icon" value="1" onchange="asd();">One</label>
<label id="2"><input type="radio" name="icon" value="2" onchange="asd();">Two</label>

Alternatively, you can use Javascript to add the event listener automatically.

Also this line:

window.parent.document.getElementById("images").getElementsByTagName("img")[0].src = "images/lang/" + qwer  + ".png";

is not right, getElementById already returns the image you need so getElementById("images").src = ... will do the trick.

dark_charlie
I just change ..onchange="asd();"> to ...onclick="asd();"> Maybe that is not best solution, but it working. :)
simple