SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy IE not accepting JS code BUT FF,Google Chrome and Safari is Happy with same JS code

    Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="sha512.js"></script>
    <script type="text/javascript">
    function formhash(form, password) {
    	
       // Create a new element input, this will be out hashed password field.
       var p = document.createElement("input");
       // Add the new element to our form.
       form.appendChild(p);
       p.name = "p";
       p.type = "hidden"
       p.value = hex_sha512(password.value);
       // Make sure the plaintext password doesn't get sent.
       password.value = "";
       // Finally submit the form.
       form.submit();
    
    }
    </script>
    <?php
    if(isset($_GET['error'])) { 
       echo 'Error Logging In!';
    }
    ?>
    
    </head>
    
    <body><form action="process_login.php" method="post" name="login_form">
       Email: <input type="text" name="email" /><br />
       Password: <input type="password" name="password" id="password"/><br />
       <input type="button" value="Login" onclick="formhash(this.form, this.form.password);" />
    </form>
    </body>
    </html>
    What is wrong in this code...?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I'm really surprised the other browsers worked. form.submit and form.appendChild are not valid. As the name of your form is login_form.
    I'd try login_form.appendChild(p) and login_form.submit();

  3. #3
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,264
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    I think the problem is that IE doesn't let you set an input element's type after the element has been created.

    Give this a try:

    Code:
       // Create a new element input, this will be out hashed password field.
       try {
        // try the IE way
        var p = document.createElement('<input type="hidden">');
       } catch (e) {
        // try the conventional way
        var p = document.createElement('input');
        p.type = "hidden";
       }
    "First make it work. Then make it better."

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,264
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    ...form.submit and form.appendChild are not valid. As the name of your form is login_form...
    Inside the formhash function, "form" is a variable, which would hold a reference to a form object.
    "First make it work. Then make it better."

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    Inside the formhash function, "form" is a variable, which would hold a reference to a form object.
    Interesting, good to know.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •