I want to execute this java script on load, but it doesn't seem to display the result after the browser loads.
<script>
function displayNumber()
{
var card = document.getElementById('credit').value;
var str = "";
for(var i=1; i <= card.length-4; i++) {
str += "*";
}
ecard = str + card.substr(card.length-4);
document.getElementById('output').innerHTML = ecard;
}
</script>
<form id="myform">
<input type="text" id="credit" onLoad="displayNumber()" value="123456789012">
</form>
<label id="output"> </label>
The output should be
********9012
1 Answer 1
You cannot use onload with an input. Instead, put window.onload = displayNumber; in your JavaScript. The other option is to add a body tag and use onload="displayNumber()"
answered Sep 21, 2012 at 23:59
Rhyono
2,4782 gold badges27 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js