PDA

View Full Version : [DHTML] TexTitle



jfftck
06-22-2006, 04:56 PM
1) CODE TITLE: TexTitle

2) AUTHOR NAME/NOTES: Jeffrey M. Tackett

3) DESCRIPTION: This code creates title text in textbox that is cleared when the textbox get focus.

4) URL TO EXAMPLE: http://personal.jeffreytackett.us/test.html

ATTACHED BELOW IS THE CODE:

djr33
06-22-2006, 09:59 PM
Amazingly close to what I posted here:
http://dynamicdrive.com/forums/showpost.php?p=39714&postcount=101



<input name="email" type="text" value="your@email.com" onFocus="if (this.value=='your@email.com') {this.value='';}" onBlur="if (this.value=='') {this.value='your@email.com';}">


Additionally, you wouldn't want people submitting your@email.com to the thing.
I'd suggest:
<form action="page.php" method="post" onSubmit="if (email.value=='your@email.com') {alert('Please enter your email.'); email.focus(); return false;}">

jfftck
06-22-2006, 10:42 PM
I did not look at the forums before creating this code and I made my version pull the title attribute to place in the textbox. The method I created follows the standards on how to use textboxes. http://www.w3.org/TR/2005/WD-WCAG20-HTML-TECHS-20050630/#label-title

What you are trying to say is my code is like your code is the same as the fact that there are many different versions of image gallrey DHTML code. I am sorry, but your code is not as flexable as mine. With my code you can create different styles for diffrent textboxes and yours only creates text in the textbox.

ddadmin
06-22-2006, 10:51 PM
Maybe I'm missing something, but what exactly does this script do? It seems to merely change the style of the text field depending on the state, which doesn't seem particularily useful. That's just my opinion though.

djr33
06-22-2006, 10:54 PM
Yeah, I'm a bit lost too.

Mine does exactly what yours does, except for making the text a bit faded out when it's the default value, not user entered.

I'm not accusing you of stealing it or anything.... just saying they do the same thing.

True that yours is a function, though.

jfftck
06-22-2006, 11:33 PM
You have image rollovers and this is like the same thing for textboxes, I see many sites using this same type of thing and thought that I would try and create my own code that does the same effect. Look at http://sourceforge.net/index.php to see how it can be used, they have a search box in the upper right-hand corner. This could also give more information on what to put in the textbox, I put some examples on my test page to show how it could help. This is also something all the Ajax apps have and thought that a simple funtion was something that some people would like to include in there app, just so someone does not have to reinvent the wheel. I know that this is a simple script that does not do much, but so is an image rollover.

Twey
06-23-2006, 01:08 AM
After blur occurs, the textboxes have a color but not a background-color set.

Also, you might want to do something better than simply change the text colour to signify a highlighted/non-highlighted textbox... maybe something with opacity?

I agree that this is a handy script, and generally well-written, but it uses browser detection (which, by the way, is in a completely different coding style).

jfftck
06-23-2006, 01:32 AM
You can use any class you want, I was just using a simple example. If you are wanting a fade effect, then you are free to write the code for that. This code is released under GPL. I just wanted it to be a lightweight script that did not throw errors on browsers that don't support the functions that I use (that is why I don't use the script attributes of HTML tags, but keep all of my scripts between script tags).

Twey
06-23-2006, 02:10 AM
I just wanted it to be a lightweight script that did not throw errors on browsers that don't support the functions that I use (that is why I don't use the script attributes of HTML tags, but keep all of my scripts between script tags).Good practice, but that's not why you should be doing it :) Event handlers are supported by all browsers that support scripting, insofar as I'm aware; and, like all unknown HTML attributes, ignored by those that don't.

You will correct the browser detection?

jfftck
06-23-2006, 02:37 AM
Good practice, but that's not why you should be doing it :) Event handlers are supported by all browsers that support scripting, insofar as I'm aware; and, like all unknown HTML attributes, ignored by those that don't.

You will correct the browser detection?

I am working on an update, so I will test all the browsers that I can. The biggest reason for me to use the brower detection is the fact that Opera did not support javascript very well before 7 and I just did not have an old version on my computer. I will download the old verisons and see where things die, if at all.

Twey
07-04-2006, 04:28 PM
The biggest reason for me to use the brower detection is the fact that Opera did not support javascript very well before 7 and I just did not have an old version on my computer. I will download the old verisons and see where things die, if at all.This is what feature detection is for. For example, say Opera 7 lacks the getElementById() function. You can, as you have done, check to see if the user is running Opera 7, and if so not use getElementById(). That's browser detection, which is what you have done. The problem is that some other browsers might also lack getElementById(). So, instead, you should use a test statement such as the following:
if(typeof document.getElementById === "function") {
// ... getElementById()-requiring code...
}This is known as feature detection, and is a much better idea.