0

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>

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by alex.tepes
0

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>

Edited by alex.tepes: typo...

This topic has been dead for over six months. 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.