What's Here?
- Members: 149,626
- Replies: 506,753
- Topics: 79,851
- Snippets: 2,666
- Tutorials: 706
- Total Online: 2,012
- Members: 76
- Guests: 1,936
|
This script will change the value of a search box depending on its current value and whether or not it is currently focused. It also changes styles.
|
Submitted By: BetaWar
|
|
Rating:

|
|
Views: 299 |
Language: JavaScript
|
|
Last Modified: August 12, 2008 |
|
Instructions: Just add the script and styles to their respecitve area and give an input (text, textarea, or password) an id then add the second instance of the script to the bottom of the page with a pointer to the object (via id) inside the initSearchBox() function. |
Snippet
<style>
.active{
border: 2px solid lightblue;
color: #000;
margin: -1px;
}
.inactive{
margin: 0px;
border: 1px solid #bbb;
color: #999;
}
.blurred_active{
border: 1px solid #999;
color: #000;
margin: 0px;
}
</style>
<script>
function initSearchBox(obj){
obj.standardValue = obj.value;
obj.onfocus = function(){
if(this.value == this.standardValue){
this.value = '';
}
this.className = 'active';
}
obj.onblur = function(){
if(this.value == ''){
this.value = this.standardValue;
this.className = 'inactive';
}
else{
this.className = 'blurred_active';
}
}
}
</script>
<input type="text" class="inactive" name="txt" id="t" value="Search..." />
<script>
initSearchBox(document.getElementById('t'));
</script>
Copy & Paste
|
|
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|