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

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()"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.