Reputation: 2441
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
Upvotes: 0
Views: 77
Reputation: 2468
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()"
Upvotes: 2