Saturday, September 14, 2019

Get value from attribute with javascript

Answer




I have the following code:



echo "
";


In this case, val has the value 8.



I want to access this value with javascript. I have tried the followin method, but it keeps saying that txt is null.



  


Anyone who can help me?



EDIT:
I solved the problem by placing the code inside window.onload:




    window.onload = function() {
var txt = document.getElementById("hp");
var f = txt.getAttribute('val');
alert(f);
};

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...