0

Hello,
I am trying to build a function that takes the input of the IBAN field (alphanumeric), counts them and compares the to the needed value (24). Then, if don't match it triggers an error message, if they match it does nothing.
This is the code:

<script type="text/javascript">
function checkIBAN(iban)
{
var iban = document.getElementById('IBAN').lenght;
if (iban != 24)
{
alert('El format no és correcte');
return false;
}
else
{
return true;
}
}
</script>

This is the trigger:
onblur="checkIBAN('IBAN');"
However, it is not working. I'm just learning Javascript, so it may be a silly question. Can anyone help?
Thanks!

Dani

3
Contributors
3
Replies
16
Views
3 Years
Discussion Span
Last Post by acrocephalus
0

lenght should be length, but the element itself does not have a length. You need: document.getElementById('IBAN').innerHTML.length IIRC.

0

There's a typo in your first line. Also you are passing the parameter but not using it. Which is not a problem, but just to keep it clean, we can remove it too. Find the corrections below -

function checkIBAN()
{
                var iban = document.getElementById('IBAN').value.length;

                if (iban != 24)
                {
                    alert('El format no és correcte');
                    return false;
                }
                else
                {
                    return true;
                }
}

and the trigger

onblur="checkIBAN();"
0

Thanks for your quick reply! I should check for typos next time... I've used the network18, the code looks much cleaner.
Thanks!

Dani

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.