hmmm, they look like good solutions Dave... but I've have just returned to this post with what I came up with, and it works
It's a bit long, but it's because of the commenting and ability to swap styles as well
JavaScript:
<script type="text/javascript">
function inputSwap(oldObject, newType, theValue) {
// create and set type of new input element
var newObject = document.createElement('input');
newObject.type = newType;
// set styles to be applied
var placeholderColor = '#999999';
var textColor = '#333333';
var placeholderStyle = 'italic';
var textStyle = 'normal';
// retain attribute values of old object
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.name) newObject.name = oldObject.name;
if(oldObject.id) newObject.id = oldObject.id;
if(oldObject.className) newObject.className = oldObject.className;
// swap values and styles
if(oldObject.value==theValue) {
newObject.value = '';
newObject.style.color = textColor;
newObject.style.fontStyle = textStyle;
}
if(oldObject.value=='') {
newObject.value = theValue;
newObject.style.color = placeholderColor;
newObject.style.fontStyle = placeholderStyle;
}
// replace object
oldObject.parentNode.replaceChild(newObject,oldObject);
// set focus
newObject.focus();
return newObject;
}
</script>
HTML:
<form action="login.php" method="post">
<input type="text" class="input" name="txtHandle" id="txtHandle" value="Username" onclick="inputSwap(this, 'text', this.value);" onfocus="inputSwap(this, 'text', this.value);" />
<input type="text" name="txtPassword" id="txtPassword" value="Password" onclick="inputSwap(this, 'password', this.value);" onfocus="inputSwap(this, 'password', this.value);" />
<input name="submit" type="image" src="btnIndexLogin.png" id="btnLogin" value="Login" />
</form>
Any thoughts/feedback?