Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  112] [ 7]  / answers: 1 / hits: 30420  / 6 Years ago, fri, august 10, 2018, 12:00:00

Do I want to know why my script is not taken the id value?



I used this code in a separate folder in a single file that was named by test.js
this is my starting code.



var myInput = document.getElementById(newPass);
var confInput = document.getElementById(confpsw);
var letter = document.getElementById(letter);
var capital = document.getElementById(capital);
var number = document.getElementById(number);
var length = document.getElementById(length);
var special = document.getElementById(special);
document.getElementById(Button).disabled = true;


my view code is..



<button id=Button class=btn btn-lg btn-primary btn-block btn-signin type=submit>Submit</button>


I got the error like this...



Uncaught TypeError: Cannot set property 'disabled' of null



why my script is not working in cshtml?


More From » c#

 Answers
26

It seems the code is running before the DOM is ready. Try with DOMContentLoaded.




The DOMContentLoaded event is fired when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.




document.addEventListener(DOMContentLoaded, function(event) {
document.getElementById(Button).disabled = true;
});

[#53759] Tuesday, August 7, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
krystadesiraeo

Total Points: 493
Total Questions: 93
Total Answers: 100

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;