Hi guys.
I'm making my own javascript. Basically, I want a text box to clear, ready for user input, when the user clicks on it. Ideally, I'd like an if statement in there, so the text box is only cleared if it's still the default message there - i.e. I don't want the user's typing cleared when they re-click on it, you see.
This is what I've made so far:
In the head:
Code:
<script language="Javascript">
<!-- Script to clear initial text box values
function clearfriendname {
if(document.refer.friendname.value="Friend's name"){
document.refer.friendname.value=""
}
}
function clearfriendemail {
if(document.refer.friendemail.value="Friend's email"){
document.refer.friendemail.value=""
}
}
//-->
</script>
And in the body:
Code:
<form name="refer">
<p align="center"><input type="text" size="15" name="friendname"
value="Friend's name" onclick="clearfriendname()"><br>
<input type="text" name="friendemail" size="15" value="Friend's email"
onclick="clearfriendemail()"><br>
<input type="button" value="Send"></p>
</form>
Unfortunately, it doesn't work. I get an 'object expected' error. I'm sure its just some simple Javascript programming standard that I'm getting wrong, or something like that. I'm afraid I've only learnt javascript from picking random chunks up over the years, so I don't have a particularly good knowledge of it, and the proper practices associated with it.
Thanks a lot,
Wicko
|