Sudarshan Taparia
Sudarshan Taparia

Reputation: 183

Onload event on <form> tag

I want a JavaScript function to execute when the page loads.

I added an onload attribute to my <form> tag, but the alert is not executed.

What am I doing wrong?

<form name=myfm method=post action=quiz.php onload = alert('hello')>

Upvotes: 11

Views: 46319

Answers (2)

Careen
Careen

Reputation: 567

//  javaScript
window.onload = function{
   alert("loaded");
}


//  jquery
 $(document).ready(function() {
    $("#div-id").click(function(){ 
    alert("the page is loaded");
    }); 
});

Upvotes: 4

TheSk8rJesus
TheSk8rJesus

Reputation: 418

try adding the onload to the body tag

<body onload="alert('Hello World')">

Upvotes: 12

Related Questions