Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS working fine in FireFox,GooleChrome,Safar BUT NOT in IE 1

Status
Not open for further replies.

vishalonne

Technical User
Jul 29, 2012
49
Hello All

I am trying to just test a simple javascript code.
Following Code is working very fine in FF-14, Google Chrome - 21, Safari - 3.2 But not in IE 8

JavaScript:
<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 mistake I am doing...?
 
Its actually more an IE thing. IE doesn't like to change the type property of inputs once they've been appended to the document. The simple fix would be to just swap around the appendchild() call so it comes after the property settings.

Code:
p[COLOR=#990000].[/color]name [COLOR=#990000]=[/color] [COLOR=#FF0000]"p"[/color][COLOR=#990000];[/color]
   p[COLOR=#990000].[/color]type [COLOR=#990000]=[/color] [COLOR=#FF0000]"hidden"[/color]
   p[COLOR=#990000].[/color]value [COLOR=#990000]=[/color] [b][COLOR=#000000]hex_sha512[/color][/b][COLOR=#990000]([/color]password[COLOR=#990000].[/color]value[COLOR=#990000]);[/color]
   form[COLOR=#990000].[/color][b][COLOR=#000000]appendChild[/color][/b][COLOR=#990000]([/color]p[COLOR=#990000]);[/color]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thank you Vacunita You are right. Problem is solved by your suggestion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top