How to change the background color of all <form> elements when page load in JavaScript

1 Answer

0 votes
<!DOCTYPE html>        
<html>
<head>
</head>
<body onload="set_bk_color()">

<form id="aaa_id">
    <input type="button" onclick="alert(document.forms[0].id);" value="aaa form" />
</form>

<form id="bbb_id">
    <input type="button" onclick="alert(document.forms[1].id);" value="bbb form" />
</form>

<form id="ccc_id">
    <input type="button" onclick="alert(document.forms[2].id);" value="ccc form" />
</form>
<script type="text/JavaScript">   

function set_bk_color()
{
    for (var i = 0; i < document.forms.length; i++) 
        document.forms[i].style.backgroundColor = 'BLUE';
}


/*
run:

check your browser

*/

</script>
</body>
</html>

 



answered Jun 9, 2016 by avibootz

Related questions

...