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

Recommended Answers

All 3 Replies

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

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

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

Dani

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.