943,838 Members | Top Members by Rank

Ad:
Nov 30th, 2008
0

Text box mouseover

Expand Post »
Hi y'all. I'm just starting to learn HTML and just had a few questions. I was using some tutorials from w3schools.com, and I came across Event Attributes. So I have this textbox, and I want it, when clicked, to clear the the text box of it's value, and change the text color to black (as in the actual text box, not the whole screen). Then when you click out of the text box, I want it to change the text color back to grey and have the value of the text box be 'Email' again. Also, how do I change the font? Here's the code:

html Syntax (Toggle Plain Text)
  1. <form>
  2. <input type="text" value="Email" name="Email"
  3. style="color:grey;text-align:left;background:white">
  4. </form>

Thanks!
Last edited by peter_budo; Dec 3rd, 2008 at 7:32 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
besktrap is offline Offline
58 posts
since Jul 2008
Nov 30th, 2008
0

Re: Text box mouseover

HTML itself can provide you all the elements you need. But with dynamic changes, you will be needing some script for this to generate the output you need. Perhaps you can start with DHTML.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Dec 6th, 2008
0

Re: Text box mouseover

Some of that (changing the colors of the text and whatnot) you can do with CSS styles. The rest (changing the actual text) requires that you use a scripting language like Javascript.

For the styling (changing text color, background color, etc) you can apply a style to input buttons. With pseudo classes, you can have that style change based on whether it's being targeted (in focus) or not.

For example, put this in the <head> section of your page, and test it out with an <input type="text"> element...

html Syntax (Toggle Plain Text)
  1. <style type="text/css">
  2. input { color: #ccc; background-color: #eee; }
  3. input:focus { color: #000; background-color: #fff; }
  4. </style>

The style applied to input:focus will only be applied when the input class is selected. The rest of the time, it will display what is declared for all inputs, and so it looks like it's inactive.

To alter the text inside the input, you'll need to use javascript. Posting in the javascript forum might get you some more specific help, but here's a nudge in the right direction.

Get a javascript framework, like jquery, to make it easier to select elements from the DOM.

jQuery has two methods to help you. The focus() method will trigger when an item is selected, and at that point you could clear the input and alter its style. The blur() method will trigger when the focus leaves the input, and at that point you could replace the text with "E-mail" and alter the style again.

Good luck,
- Walkere
Reputation Points: 29
Solved Threads: 5
Junior Poster in Training
Walkere is offline Offline
57 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: button text...
Next Thread in HTML and CSS Forum Timeline: Plan for parsing HTML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC