For example, I have a text input with a value of "insert text here" like this:
<input type="text" value="insert text here" />
When I click on the block of the input, then the text of "insert text here" will automatically disappear, but when the user cancel to write something there, the text will appear again.
How to do this?
Thanks
USE placeholder attribute
<input name="" type="text" placeholder="place holder text here."/>
but it may not work in older browser. if you are for older browser as well than you should use javascrip/jquery for dealing with this problem.
<input type="text" class="userName" value="Type User Name..." />
$(document).ready(function(){
$('.userName').on('focus',function(){
var placeHolder = $(this).val();
if(placeHolder == "Type User Name..."){
$(this).val("");
}
});
$('.userName').on('blur',function(){
var placeHolder = $(this).val();
if(placeHolder == ""){
$(this).val("Type User Name...");
}
});
});
see deme JSFIDDLE
Use this placeholder attribute
<input type="text" placeholder="insert text here" />
<input type="text" name="fname" placeholder="insert text here">
You need to use the "placeholder" attribute like so:
<input type="text" placeholder="insert text here" />
The placeholder text will be automatically deleted when typing something in the field
http://www.w3schools.com/tags/att_input_placeholder.asp
use a placeholder instead of value.
<input type="text" placeholder="insert text here" />
You can achieve this using Placehoder
but u need to be aware of Older versions of browsers, because it doesn't supports the place hoder
<input type="text" value="some text" placeholder="insert text here"/>
for older versions of browser u can use the below link and download the js
link
If you want compatible in all browsers then you can use this code.
<!DOCTYPE html>
<html>
<body>
First Name: <input type="text" id="myText" placeholder="Name">
<p>Click the button to display the placeholder text of the text field.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myText").placeholder;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
Related
Using html for my page I have a text box and a submit button. I want to be able to put an image url into the text box, click submit, and have the image display below the submit button. I DO NOT want to upload a picture as a file. I have looked around for how to do this but have not had any luck. Any ideas?
<form>
<input type="text" name="imglink" value="insert image URL here" onclick="this.select()"><br>
<input type="submit" value="Load Image">
</form>
Here is another example, with pure Javascript. Instead of "submit" i used "button" to not submit the form.
<form action="#" method="post">
<input type="url" name="imglink" id="imglink" placeholder="Insert image URL here" /><br>
<input type="button" value="Show Image" id="btn1" />
</form>
<div id="photo"></div>
<script>
document.getElementById('btn1').addEventListener('click', function(){
document.getElementById('photo').innerHTML = '<img src="'+ document.getElementById('imglink').value +'" alt="Image" />';
});
</script>
Something like this will allow you to enter a url and upload under your submit button. Ensure that you have jquery available for this to work.
https://jsfiddle.net/7L031bfj/
HTML
<form>
<input type="text" id="input">
<button type="button" id="submit">Submit</button>
</form>
<div id="photo"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
JS
$('#submit').click(function(){
var photo = $('#input').val();
$('#photo').append('<img src=' + photo + '>')
});
Instead of using text box, you can use this Attribute <input type="file">.
Is this what you want, as i am also slightly unclear as what you want
https://jsfiddle.net/q65rxcbg/
<input type="text" id='imglink' value="insert image URL here">
<br>
<input type="submit" id='submit' value="Load Image">
<br/>
<img id='photo'>
$('#submit').click(function () {
var selectedFile = $('#imglink').val();
$('#photo').attr("src", selectedFile);
});
I have an input field in which you can type some text. It has some default text:
<input type="text" id="text" value="Type some text here" maxlength="35" tabindex="10">
I want to make the default text disappear when the user clicks on the default text or inside the input field.
How can I do this?
Try using the placeholder attribute (placeholder="Your Text" instead of value="Your Text"):
<input type="text" id="text" maxlength="35" tabindex="10" placeholder="Type some text here">
Note: Placeholder attribute doesn't work in IE8/9, or Opera Mini (http://caniuse.com/#feat=input-placeholder).
Use the placeholder attribute
<input type="text" id="text" value="" maxlength="35" tabindex="10" placeholder="Type some text here">
If you want to support older browsers:
<input type="text" id="text" value="Type some text here" maxlength="35" tabindex="10" onclick="this.value = (this.value == 'Type some text here' ? '' : this.value);">
http://jsfiddle.net/gLjt98af/
1) Using placeholder attribute
You can use placeholder attribute as shown below. It will show as long as you don't click inside the text box. Once you type anything inside it, the text will disappear.
HTML
<input type="text" id="text" placeholder="Type some text here" maxlength="35" tabindex="10">
2) Using java script function
HTML
<input type="text" id="text" value="Type some text here" maxlength="35" tabindex="10"
onclick='cleartext()' onblur='settext()'>
JS
function cleartext(){
document.getElementById('text').value= '';
}
function settext(){
if(document.getElementById('text').value=== ''){
document.getElementById('text').value= 'Type some text here'
}
}
Instead of using the placeholder attribute you can also try this:
<input type="text" value="Type some text here" onfocus="if (this.value == 'Type some text here') {this.value=''}" />
Is it possible that when I check a checkbox it redirects me directly to a textbox ?
Like if I did a TAB when I check it.
And if possible only with HTML and CSS
You can't do it with just HTML & CSS
but here is a solution using javascript:
window.onload = function() {
var checkbox = document.getElementById("agree"),
textbox = document.getElementById("textbox");
checkbox.onclick = function() {
if(this.checked) {
textbox.focus();
}
};
};
demo
Maybe the minimal implementation would be:
<form name="f1">
<input id="in1" name="in1" type="checkbox" onClick="if(this.checked) document.f1.in2.focus()" /> Check option <br/>
<input id="in2" name="in2" type="text" />
</form>
Fiddle demo
The simpliest way is to use TabIndex attribut in the input element
<input type="checkbox" Tabindex="1"> </input>
<br>
<br>
<input type="text" Tabindex="2"> </input>
I hope this might help you
I am creating a websites, and I have came across a predicament with my coding.
I am writing a 'submit form' and I need it to look like the following example:
Message: (Gives the user to submit a message, or type any comments) And inside the text box, I'd like for it to say 'Type your message here' but when you click within the box, the 'type your message here' disappears. I also would like to be able to control how large this text box is.
Name: Type your first and last name here (I want it to function the same as above)
Email Address: Type your email address here: (Again, function same as above)
This, is the code that I have so far, and I am not sure if it's correct or not, for what I'm trying to do:
<form method="post" action="mailto:youremail#youremail.com" >
<b>Message:</b><br><input type="textbox" value="text_name" onfocus="if (this.value=='Text_name') this.value='';" style="width: 300px;" style="height: 300px;"/><br/>
<b>Name:</b><br><input type="text" name="First and Last" size="30" maxlength="30" /><br />
<b>Email:</b><br><input type="text" name="Email" size="24" maxlength="24" /><br />
<input type="submit" value="Send Email" />
</form>
There are lots of plugins available fir this. But you can use a HTML5 property "placeholder"
<input type="text" placeholder="Enter your name...">
HERE is the demo. Text/hint will diappear as you start typing.
<b>Message:</b><br><input type="textbox" placeholder="Type your message here" style="width: 300px;" style="height: 300px;"/><br/>
<b>Name:</b><br><input type="text" name="First and Last" size="30" maxlength="30" placeholder="Type your first and last name here" /><br />
<b>Email:</b><br><input type="text" name="Email" size="24" maxlength="24" placeholder="Type your email address here"/><br />
<input type="submit" value="Send Email" />
From my understanding this is pretty much a duplicate of: Onclick event to remove default value in a text input field right?
If you are fine with HTML5 then you can use placeholder otherwise you will need to use Javascript that removes the text onblur
I suggest you to use bootstrap css for better styling. Just have a look at this http://getbootstrap.com/css/ . I hope this would be helpful for you
You can define a script and use the below function since it can be used for both onfocus and onblur,
function clearText(field) {
if(field.defaultValue == field.value) {
field.value = “”;
}
else
if(field.value == “”) {
field.value = field.defaultValue;
}
}
I want to provide the user with a hint on what he needs to enter into my text field. However, when I set the value, it does not disappear once a user clicks on the text field. How can you make it disappear?
<form action="input_password.htm">
<p>Username:<br><input name="Username" value="Enter username.." type="text" size="20" maxlength="20"></p>
</form>
With a bit of JavaScript:
<input
value="Enter username..."
onfocus="if (this.value === 'Enter username...') this.value=''" ... />
HTML5 has a nice attribute for this, called placeholder:
<input placeholder="Enter username.." ... />
but this attribute is not supported in old browsers.
the best way to give a hint is placeholder like this:
<input.... placeholder="hint".../>
You'd need attach an onFocus event to the input field via Javascript:
<input type="text" onfocus="this.value=''" value="..." ... />
I think for your situation, the easy and simple for your html input , you can
probably add the attribute title
<input name="Username" value="Enter username.." type="text" size="20" maxlength="20" title="enter username">
With HTML5, you can now use the placeholder attribute like this:
<form action="demo_form.asp">
<input type="text" name="fname" placeholder="First name"><br>
<input type="text" name="lname" placeholder="Last name"><br>
<input type="submit" value="Submit">
</form>
http://www.w3schools.com/tags/att_input_placeholder.asp
I have the same problem, and I have add this code to my application and its work fine for me.
step -1 : added the jquery.placeholder.js plugin
step -2 :write the below code in your area.
$(function () {
$('input, textarea').placeholder();
});
And now I can see placeholders on the input boxes!
This is exactly what you want
$(document).tooltip({ selector: "[title]",
placement: "top",
trigger: "focus",
animation: false});
<form id="form">
<label for="myinput1">Browser tooltip appears on hover but disappears on clicking the input field. But this one persists while user is typing within the field</label>
<input id="myinput1" type="text" title="This tooltip persists" />
<input id="myinput2" type="text" title="This one also" />
</form>
[ref]
If you mean like a text in the background, I'd say you use a label with the input field and position it on the input using CSS, of course. With JS, you fade out the label when the input receives values and fade it in when the input is empty. In this way, it is not possible for the user to submit the description, whether by accident or intent.
If you don't insist on the hint being displayed inside the input field, a modern solution would use a label element with the for attribute referring to the id of the input field, like this:
<form action="input_password.htm">
<label for="username" title="This is your user name...">Username: </label><input id="username" name="Username" type="text" size="20" maxlength="20"></p>
</form>
If you click the label, the input field will get the input focus.
If you hover over the label, it will show a longer explanation.
Generally the label should describe well enough what the user has to enter (in the case of user name it should be very much obvious).
Define tooltip text
<input type="text" id="firstname" name="firstname" tooltipText="Type in your firstname in this box">
Initialize and configure the script
<script type="text/javascript">
var tooltipObj = new DHTMLgoodies_formTooltip();
tooltipObj.setTooltipPosition('right');
tooltipObj.setPageBgColor('#EEE');
tooltipObj.setCloseMessage('Exit');
tooltipObj.initFormFieldTooltip();
</script>