/    Sign up×
Community /Pin to ProfileBookmark

Changing value into a placeholder

I have a search bar with a value of “USA” and I want that value to change into a placeholder that says
“Anywhere in the world” when click inside the input form.

How can I do that ?

to post a comment
HTML

5 Comments(s)

Copy linkTweet thisAlerts:
@shakilapervinJul 08.2019 — Please send me your code
Copy linkTweet thisAlerts:
@NogDogJul 08.2019 — Warning: I am not a JavaScript expert. However, this seems to work:
<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=""&gt;
&lt;label for="test"&gt;Test:&lt;/label&gt;
&lt;input type="text" name="test" placeholder="Anywhere in the world" value="USA"
onfocus="this.value = '';" onblur="if(this.value == ''){this.value='USA';}"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@daveyerwinJul 08.2019 — ``<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style&gt;
form{display:inline-block;}
fieldset{
border: 0.1em solid black;
position: relative;
margin-top:1.4em;
background-color: #ddd
}
legend {
margin:0.2 em;
position: absolute;
top: -1.20em;
background-color: #ddd;
border:0.1em solid;border-top-left-radius:.4em;
border-top-right-radius:.4em;border-bottom:none ;
}
&lt;/style&gt;

&lt;form&gt;
&lt;fieldset&gt;
&lt;legend&gt; Seach Bar &lt;/legend&gt;
&lt;label&gt; pick some place:
&lt;input value=USA placeholder="Anywhere in the world"&gt;
&lt;/label&gt;
&lt;/fieldset&gt;
&lt;/form&gt;
&lt;script&gt;
document.forms[0].onclick=function(){this.elements[1].value=''}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@codyhillauthorJul 09.2019 — @DaveyErwin#1606021 none of those work, this is my code.
&lt;div class="form-container"&gt;
&lt;form action="#" class="form"&gt;
&lt;input value="Try &amp;quot;Los Angeles, Buckingham Rd&amp;quot;" aria-label="search" placeholder="dsfvqdsf" type="text"&gt;
&lt;button&gt;&lt;i class="fas fa-search"&gt;&lt;/i&gt;&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
Copy linkTweet thisAlerts:
@daveyerwinJul 09.2019 — ``<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;&lt;/title&gt;


&lt;div class="form-container"&gt;
&lt;form action="#" class="form"&gt;
&lt;input value="Try &amp;quot;Los Angeles, Buckingham Rd&amp;quot;" aria-label="search" placeholder="dsfvqdsf" type="text"&gt;
&lt;button&gt;&lt;i class="fas fa-search"&gt;&lt;/i&gt;&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;script&gt;
document.forms[0].elements[0].onclick=function(){this.value=''}
&lt;/script&gt;
&lt;/html&gt;<i>
</i>
``
×

Success!

Help @codyhill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...