Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2013, 04:59 AM   PM User | #1
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Question Showing/Hiding text in search bar

HI

You know the search bar on websites that shows some default text like "Search" and when you click on it the text disappears.

Whats the best approach to do it?

Like hard code the "search" value for example:

var val = document.getElementById('txtsearch').value;
if(val == "Search"){
//code to empty the text box
}

If yes then how do you manage when you have to work on a multi-lingual website ? You cannot hard code the value for each lang. Whats the best approach in your opinion?


THanks for your inputs.
cancer10 is offline   Reply With Quote
Old 01-18-2013, 09:00 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
This is called a "placeholder" value and modern browsers support it already, so you won't have to do anything about it.

In order to fill in the default value, internationalized pages use "i18n" (=internationalization) techniques to grab language dependent values. So they are in fact not hardcoded values ... they will be dynamically created server-side so in the browser it seems to be hardcoded.
devnull69 is offline   Reply With Quote
Old 01-18-2013, 09:10 AM   PM User | #3
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Quote:
Originally Posted by devnull69 View Post
This is called a "placeholder" value and modern browsers support it already, so you won't have to do anything about it.

In order to fill in the default value, internationalized pages use "i18n" (=internationalization) techniques to grab language dependent values. So they are in fact not hardcoded values ... they will be dynamically created server-side so in the browser it seems to be hardcoded.
Where can i find the code for it?
cancer10 is offline   Reply With Quote
Old 01-19-2013, 06:07 AM   PM User | #4
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Perhaps I have found a solution: http://jsbin.com/eguluv/3/edit
cancer10 is offline   Reply With Quote
Old 01-19-2013, 07:48 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Examples:-


Code:
<input type = "text" name = "uname" id = "uname" value = "Name: "  onclick = "if (this.value == 'Name: ') this.value = '';"  onblur = "if (this.value == '') this.value = 'Name: ';" />
<br>

<input type = "text" name = "email" id = "email" value = "Email: "  onclick = "if (this.value == 'Email: ') this.value = '';"  onblur = "if (this.value == '') this.value = 'Email: ';" />
Code:
<input type = "text" name = "uname" id = "uname" size = "40" value = "Enter user name here:-"; style=color:'#848484'; 
onclick = "if (this.value == 'Enter user name here:-') {this.value = '';this.style.color='#000000'}"
onblur = "if (this.value == '') {this.value = 'Enter user name here:-';this.style.color='#848484'}" />
A couple of errors cost us two goals and that was all that was good about the game. - Football team coach
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 01-19-2013 at 07:53 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:45 PM.


Advertisement
Log in to turn off these ads.