Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why Isn't this javascript code working?
#1
I created a html document in which i added a predefined text in the textbox like "enter name here"
I created a function to delete the text when user clicks the input.
But , it had one problem that whenever user types his data and when he clicks the input then all his data is deleted. To prevent this used this method but this is not working , I don't know why.
here's the code

Code:
<!DOCTYPE html>
<html>

<head>


<script type="text/javascript">
function emptyfield(field){
field.value = "";
}

if(document.frmlogin.box.value != "Enter Username Here"){
frmlogin.box.onclick = "";
}
</script>
</head>

<body>

<form name="frmlogin" >
Username: <input type="text" id="cool" value="Enter Username Here" name="box" onclick="emptyfield(document.frmlogin.bo… />
</form>
</body>
</html>
I could have done it very easily using just one function by i want to know what is wrong in this.
I don't want alternative methods of doing it, i want to know what is wrong in this?

-Himansh
The Power to Believe in Yourself is the Power to change the Fate!


Messages In This Thread
Why Isn't this javascript code working? - by Himansh - 10-05-2012, 11:05 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)