0

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
Marko
20.6k13 gold badges51 silver badges64 bronze badges
asked Sep 21, 2012 at 23:57

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.