tommr Posted June 6, 2011 Share Posted June 6, 2011 I am looking for a javascript that will display a field name in a field box and when the box is clicked the field name dims and when the typing begins the name disappears entirely. Like this site when you go to enter the contest.. www.lightandfit.com thanks, tom Quote Link to comment https://forums.phpfreaks.com/topic/238593-form-title-in-field-script-question/ Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 Although I don't know how they did the fade-out, (ajax?) this may work: <html> <head> <script type="text/javascript"> function changeColor(color) { document.getElementById('x').style.color=color; } function clearDefault(el) { el.value = "" } </script> </head> <body> <form> <input id="x" onmousedown="changeColor('red')" onkeydown="clearDefault(this)" type="text" value="field text" size="20"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/238593-form-title-in-field-script-question/#findComment-1226127 Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 The clearDefault() function above should be: function clearDefault(el) { if (el.defaultValue==el.value) el.value = "" } Quote Link to comment https://forums.phpfreaks.com/topic/238593-form-title-in-field-script-question/#findComment-1226131 Share on other sites More sharing options...
Adam Posted June 7, 2011 Share Posted June 7, 2011 That site uses jQuery to add the effects to the inputs. Have a read up and learn some of the basics, it shouldn't be difficult to achieve what you want. You'll have a hard to time trying to animate the colour change with vanilla JS though. Quote Link to comment https://forums.phpfreaks.com/topic/238593-form-title-in-field-script-question/#findComment-1226330 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.