FIREFOX and CHROME script problems??

in my code is a simple script
that shows an error message if input value didnt meet the requirements.

the example is
register_form - name of the form
username = name of the input type text
requirement is string must be greater or equal to six
error is an id using the span tag and initially/by default is displayed none
and with the onBlur event
<input type="text" name = "username" onBlur = "CheckThis()">

my problem is.
my code totally works fine when i used Google Chrome
but when i used Firefox, the error messages wont display

is there some way to prevent or to make them work on any browsers?

code fragment:


<script language="javascript">

function CheckThis()
{
str = register_form.username.value
if(str.length < 6 )
error.style.display = "block"
else
error.style.display = "none"
}
</script>

Try to assign ID's to each element like:

<input name="username" id="username_id" />

After try:

<script language="javascript">

    function CheckThis()
    {
        username_element=document.getElementById("username_id");
        error_element=document.getElementById("error_div_id");

        str = username_element.value
        if(str.length < 6 )

            error_element.style.display = "block"

        else

           error_element.style.display = "none"

    }

</script>
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.