I am beginner in javascript.
js file
var msgErrorPalletizedWeight = document.getElementById('msgError');
function palletizedWeightValidation() {
console.log("hello");
/*ERROR*/ msgErrorPalletizedWeight.innerHTML += ("Please enter all the values marked with *");
}
HTML
<head runat="server">
<title></title>
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
<script src="Scripts/file.js" type="text/javascript"></script>
</head>
<body>
<p id="msgError"></p>
<asp:Button ID="btnSubmitPalletized" runat="server" Text="Submit"
OnClientClick="palletizedWeightValidation()" />
</body>
ERROR
Cannot read property ‘innerHTML’ of null
I searched many sites before asking here, they all recommending to check for null before validations which I can do but my problem here is I want to add some text to the p tag as you can see.. How to achieve that? I even tried appending, thought it might solve the problem. I know this is a silly mistake because there are many posts on this… the thing is that I cant understand where I am going wrong.
Please help.
You are
tryingto access theelementof html when it is notready, put the statement in event function to get the element in functionpalletizedWeightValidation.EDIT To stop postback, you need to return false from javascrip function.