JoJo
JoJo

Reputation: 4923

Can I use getElementById to change it's onclick event value?

<script type="text/javascript">
    window.onload = function() {
        document.getElementById('finalize_btn_top').onclick='bmlAuth();';
        document.getElementById('finalize_btn_bottom').onclick='bmlAuth();';
    }

    function bmlAuth(){
        //
    }
</script>

I studied google search results and this should work but it is not working. I put it at the bottom of the page just to be sure the elements have loaded.

<input id="finalize_btn_bottom" type="image" name="" value="continue" onmouseover="this.src='<% =strFolder %>/images/b_submitorder_on.gif';" onmouseout="this.src='<% =strFolder %>/images/b_submitorder_off.gif'" src="<% =strFolder %>/images/b_submitorder_off.gif" alt="continue" onclick="bml_submit();">

What do I need to do different?

Thanks much!

Upvotes: 0

Views: 1648

Answers (1)

Blender
Blender

Reputation: 298106

Try passing in a function reference:

var $ = document.getElementById;

$('finalize_btn_top').onclick = bmlAuth;
$('finalize_btn_bottom').onclick = bmlAuth;

Upvotes: 2

Related Questions