Redlightpacket Posted August 7, 2008 Share Posted August 7, 2008 I want a textbox to delete the text I got in it when I click in it. Then I type in what I got to type. I need code to do this. Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/ Share on other sites More sharing options...
dezkit Posted August 7, 2008 Share Posted August 7, 2008 javascript Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-610998 Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 This is Javascript, but whatever. First of all, give the textarea an ID like "sometextarea" with the id attribute. Then do: <textarea id="sometextarea" onFocus="clear('sometextarea')">Enter some text!</textarea> Then the Javascript would be: <script type="text/javascript"> function clear(name) { elem = document.getElementById(name); if (elem.value = elem.defaultValue) { elem.value = ''; } } </script> Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-610999 Share on other sites More sharing options...
Stooney Posted August 7, 2008 Share Posted August 7, 2008 I'm not good with javascript, but couldn't you make it easier by doing something like: <textarea id="sometextarea" onFocus="this.value=''">Enter some text!</textarea> I could always be wrong as usual Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-611008 Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 Then you'd be removing the value even if they already entered their value then refocused. And my script doesn't want to work for some reason, but I'll fix it in a few minutes. Gotta go get something. xD Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-611019 Share on other sites More sharing options...
Stooney Posted August 7, 2008 Share Posted August 7, 2008 True you have a point. I didn't quite think that out all the way. Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-611023 Share on other sites More sharing options...
Redlightpacket Posted August 7, 2008 Author Share Posted August 7, 2008 what do you call this in javascript? Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-611028 Share on other sites More sharing options...
Redlightpacket Posted August 7, 2008 Author Share Posted August 7, 2008 I found some code on the net, but thanks for helping. http://javascript.programmershelp.co.uk/cleartextjs.php Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-611032 Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 LOL turns out that functions named "clear" don't work. =P Link to comment https://forums.phpfreaks.com/topic/118675-making-a-text-box-do-something-question/#findComment-611050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.