I have a javascript function:
function testCreditCard () {
myCardNo = document.getElementById('ccnumber').value;
myCardType = document.getElementById('ccType').value;
if (checkCreditCard (myCardNo,myCardType)) {
alert ("Credit card has a valid format")
}
else {
alert (ccErrors[ccErrorNo])
};
}
and an input field <input type="text" id="ccnumber" />
and the script function is triggered using an onclick function
<button type="post" id="btn_c" name="btn_c" onclick="testCreditCard();" >Click</button>
Is there anyway I could trigger the function on focus out/right after filling the input field?
Im new to javascript / jquery.Please suggest a solution for this.Thank You
Tried this
<input type="text" id="ccnumber" />
<script> //Script for testCreditCard </script>
<script>$("#ccnumber").on("change", testCreditCard);</script>
<script>
function testCreditCard () {
myCardNo = document.getElementById('ccnumber').value;
myCardType = document.getElementById('ccType').value;
if (checkCreditCard (myCardNo,myCardType)) {
}
else {alert (ccErrors[ccErrorNo])};
}
</script>
</body>
But didnt work.
Bind to the change or blur event
$("#ccnumber").on("change", testCreditCard);
why you don't try to call onblur property of the input text?
<input type="text" onblur="testCreditCard()" id="id" name="id" />
when the focus is out of the text the js function is activated
my apologies for my english
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With