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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Safari browser and onClick

Status
Not open for further replies.

aforstie

Programmer
Jun 19, 2006
19
US
Below is a set of code that works well except for Safari and IE on the Mac.

First you can see that I have an input element where the type is text and onFocus it call buildElement.

<input name="password" id="password" value="Password" type="text" onFocus="buildElement()" class="regtextbox" size="10" maxlength="20"/>

Here you can see that I am going into the DOM and replacing the input element with a password type.

function buildElement() {
removeElement(document.getElementById("password"));
addElement();
}
function removeElement(obj) {
obj.parentNode.removeChild(obj)
}
function addElement() {
inputElement = document.createElement("input");
inputElement.setAttribute("name","password");
inputElement.setAttribute("id","password");
inputElement.setAttribute("value","");
inputElement.setAttribute("type","password");
inputElement.setAttribute("size","10");
document.getElementById("password-span").appendChild(inputElement);
// need to use className and maxLength instead of setAttribute to work in IE
document.getElementById("password").className = "regtextbox";
document.getElementById("password").maxLength = "20";
document.getElementById("password").focus();
// needs to be called twice to work in IE
document.getElementById("password").focus();
}

When you submit the form I then call the js below to validate the required data and Safari chokes on the test and I am assuming that it fails on the e.type != "password".

if (e.name == "password") {
field_name = SignInLang.PASSWORD;
if (e.value == '' || e.value == null || (e.value == SignInLang.PASSWORD && e.type != "password"))
error += "\n" + field_name;
}

I am not that familiar with Safari so I am not sure why this is happening. Does anyone know why it might be failing here? Or, does anyone know if Safari has a DOM viewer that I can install to see how it handles it?
 
See my thread, "Enabling "developer" options in Safari" (thread253-1143968) for more info on debugging with Safari.

Also, try alerting "e.type" to see what Safari returns.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top