joel2k8 Posted May 30, 2008 Share Posted May 30, 2008 Hello People, Im having trouble with my php form, It works and everything The thing is that i want to do, Do you no the Text Box, Its automaticaly got text in the box, But i want it so when a person clicks inside the text box, The text dissapears, Please Help, Thanks Heres my form: <form method="get" action="searchname.php"/> <input type="text" size="13" name="name" value="User Search" class="SearchField" onfocus="if(!this._haschanged){this.value=""};this._haschanged=true;" /> <input type="image" src="images/search.png" name="go" alt="go" class="go" title="go" /> </form> The value makes it so theres already text in the box, But i want it so when a person clicks the box the text dissapears, Thanks Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted May 30, 2008 Author Share Posted May 30, 2008 Anyone no the Code? Quote Link to comment Share on other sites More sharing options...
haku Posted May 30, 2008 Share Posted May 30, 2008 I'm sorry, I'm having troubles what you are asking. I'm assuming you are speaking English as a second language? Maybe you could try and explain it again, and I will help you if I can. By the way, it's 'know', not 'no'. 'No' is the opposite of 'yes', 'know' means to understand something. Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted May 30, 2008 Author Share Posted May 30, 2008 Ok Sorry, I'll try and Explain the Hard Way What i want to do is, When a Person goe's on my Website and See's my Text Box (Form) They would already see writing in the Text Box, Because Thats what I put in My Code (value="User Search") This is what i want to do, When a Person Clicks the Text Box the Writing Dissapears, It just takes it away and then you can write in what you want, But what it doe's now is when a Person clicks the Text Box, The writing Doesnt go away, I want it automatically go away when a person Clicks the Text Box, Now do you understand, Sorry About first Post, I was in a Hurry :/ Quote Link to comment Share on other sites More sharing options...
haku Posted May 30, 2008 Share Posted May 30, 2008 Ah yes, I get it. I hope you didn't take offense to my first post - I taught English as a second language for a number of years, so I'm used to writing like yours. One hint - capital letters (the bit letters) only go at the start of sentences. It looks strange to see them on every word. Anyways, here is how you can do what you want. Put this code in the head of your document: <script type="text/javascript"> function textAreaListener() { var targetTextArea = document.getElementById("target_text_area") targetTextArea.onfocus = function() { if(this.value == "some_text") { this.value = "" } } } window.onload = function() { textAreaListener() } </script> And you have to make your text area look like this: <textarea id="target_text_area">some_text</textarea> You can change the 'id' of the textarea (in this case 'target_text_area') to anything, but you have to change the id in the javascript in your head as well. You can also change 'some_text' to anything, but you also have to change that in the javascript as well. Good luck! Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted May 30, 2008 Author Share Posted May 30, 2008 Ok thanks for that But I want it in My Form that I posted, I've just tried it, In my form and it Wasnt working <form method="get" action="searchname.php"/> <input type="text" size="13" name="name" value="User Search" class="SearchField" /> <input type="image" src="images/search.png" name="go" alt="go" class="go" title="go" /> </form> Thats the Form i would want it in :/ Thanks Anyway Quote Link to comment Share on other sites More sharing options...
haku Posted May 30, 2008 Share Posted May 30, 2008 Too many capital letters! Anyways, you can use the following pattern and it will work, as long as the ID is the same as in the javascript: <input type="text" id="target_text_area" value="some_text" /> Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted May 30, 2008 Author Share Posted May 30, 2008 Ok, That worked fine, Thanks alot haku Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.