0

I have the following JavaScript code which validates a login form, and submits if it is valid. the code works on chrome and IE.
But on Firefox it doesn't show error feedback on passwordinfo and usernameinfo (document.getElementById("passwordinfo").innerText = "please enter password";)
Please help me find the problem as I am going to add ajax, and it is scaring me.

<!DOCTYPE html>
<html>
    <head>
    <link href="mystyle.css" rel="stylesheet" type="text/css"> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
    <title>welcome</title>
    <script type="text/javascript">
    function isvalidmail(mail) {
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        return filter.test(mail);
    }

    function checklogin() {
        var email = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        if(email.length < 1 || email.length > 30||(!isvalidmail(email)))
            document.getElementById("usernameinfo").innerText = "please enter valid email";
        else {
            document.getElementById("usernameinfo").innerText = "";
            if(password.length === 0) 
                document.getElementById("passwordinfo").innerText = "please enter password";
            else {
                document.getElementById("passwordinfo").innerText = "";
                document.forms["login"].submit();
            }
        }
    }
    </script>
    </head>
    <body onload="checkCookies()">
        <script>
            function checkCookies(){
                if (!navigator.cookieEnabled==true){
                    document.write("You need to enable cookies to make the site work properly.<br>Please          enable cookies and <a href='index.php'>Reload</a>");
                }
            }
        </script>
        <div id="container">
            <div id="headerpart">
                <?php include "module_header.php" ?>
            </div>
            <div id="bodypart">
                <div id="nav">      
                    <?php 
                    include 'navigation_bar.php';
                    ?>
                </div>
                <div id="mainop">
                    <span id="sessionexp"><?php if(isset($_GET["redirect"]))if($_GET["redirect"]=='session') echo         "Your Session has Expired please login"; ?></span>
                    <form id="login" action="checklogin.php" method="POST" align="center">
                        <table border="0"  bgcolor="#FFFFCB" align="center"><br/>
                            <thead>please login below</thead>
                            <tr>
                                <td>email:</td>
                                <td><input type="text" id="username" name="username"  /></td>
                                <td>
                                    <span class="warning" id="usernameinfo" name="usernameinfo">
                                        <?php
                                        if(isset($_GET["errno"]) && $_GET["errno"] == 1)
                                        echo "wrong username."
                                        ?>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td>password:</td>
                                <td><input type="password" id="password" name="password" /></td>
                                <td>
                                    <span class="warning" id="passwordinfo" name="passwordinfo">
                                        <?php
                                        if(isset($_GET["errno"]) && $_GET["errno"] == 2)
                                        echo "wrong password.";
                                        ?>
                                    </span>
                                </td>
                            </tr>
                        </table>
                        <br />

                        <input type="button" value="Login" onclick="checklogin()"/>
                        <?php echo " New User?  <a href=\"register.php\"><b>Register freely!</b></a>"; ?>
                    </form>
                </div>
            </div>
        </div>
    </body>
</html>
Jon
  • 428,835
  • 81
  • 738
  • 806
  • hi jon, I also have other pages that don't use innerhtml but the problem persists. – user3300861 Feb 12 '14 at 09:34
  • Hi and welcome to StackOverflow. It seems that you already know what's wrong: Firefox does not support `innerText`; that's because it's a *de facto* standard instead of a published one. Googling "Firefox innerText" will give you the exact same link mentioned above, you can find solutions there. – Jon Feb 12 '14 at 09:34
  • I have also removed the `ajax` tag from the question, since AJAX is unrelated to the problem you are experiencing. – Jon Feb 12 '14 at 09:36
  • No, sorry. If you need help with something specific then take some time to formulate and ask a proper question. If you don't know where to begin doing that then what you need is training, not answers. – Jon Feb 12 '14 at 10:13

3 Answers3

1

Use,

document.getElementById('passwordinfo').textContent=''; //For firefox

or try

document.getElementById('passwordinfo').innerHTML='';

For more info click HERE

Kiran RS
  • 981
  • 14
  • 31
Shashank
  • 830
  • 1
  • 6
  • 14
1

innerText is not supported in firefox. Instead try innerHTML. Let me know if that works.

Gopal
  • 378
  • 2
  • 12
0

You also could use the html attribut reguired (explain) wich is supported from the most major Browsers (only Safari not) to check the user input. For the email validation you could use the type=email propertie (explain) to validate the email input which hase the same support as the required attribut.

Andreas
  • 636
  • 1
  • 12
  • 29