Pujan
Pujan

Reputation: 3254

Code Working with Firefox but not with Chrome, Safari

Following code is working with Firefox browser but onClick is not working with Chrome and Safari.

Is there anything missing in the following code. If anyone can help so that It can work with cross browser.

Thanks.

<html><body><form method="post">
<select>
<option value="aa">Please select</option>
<option value="pst" onClick="populate();">Select Existing State</option>
</select>

<select name="abc" id="example-select" style="width: 160px;"></select>

</form>

<script type="text/javascript" language="javascript">
    var example_array = {state1 : '1# First State', state2 : '2# Secondstate', state3 : '3# Third State'}; 

    function populate() {
        var select = document.getElementById("example-select");
        for(index in example_array) {
            select.options[select.options.length] = new Option(example_array[index], index);
        }
    }
</script>
</body></html>

Upvotes: 0

Views: 253

Answers (1)

pna
pna

Reputation: 5761

well the onclick seems have some problems on webkit try to bind populate with an onchange

Upvotes: 3

Related Questions