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!
#2
Well, I am by no means a master of whatever language this is written in. However, most languages are similar.

First of all, this line:
Code:
emptyfield(document.frmlogin.bo…

Seems to be incomplete. Could you provide us with the rest of the line? Maybe that is your problem!
My Blog | My Setup | My Videos | Have a wonderful day.
#3
Sorry that i didn't write the full code
That line actually is
emptyfield(document.frmlogin.box)

By the way, thanks for showing interest in my question buy i have already understood my mistake i made in this.

If you also want to see it
Then here's the link
<!-- m --><a class="postlink" href="http://answers.yahoo.com/question/index?qid=20121005120521AAl8QSb">http://answers.yahoo.com/question/index ... 521AAl8QSb</a><!-- m -->

Read the one i chose as best answer!

-Himansh
The Power to Believe in Yourself is the Power to change the Fate!
#4
Ah, well that makes sense! Well, I'm glad that you got it figured out. But, for future reference, I recommend that you ask these type of questions on a website called "Stack Overflow" (<!-- m --><a class="postlink" href="http://stackoverflow.com/">http://stackoverflow.com/</a><!-- m -->). It is essentially Yahoo! Answers, but for programming.
My Blog | My Setup | My Videos | Have a wonderful day.
#5
Oh see, im glad that you've solved your own problem, <!-- sSmile --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt="Smile" title="Smile" /><!-- sSmile --> just keep on posting your problen and we are glad to help.


Forum Jump:


Users browsing this thread: 1 Guest(s)