HTML Input - already filled in text - html

I was wondering, is there a way to put text into an input field?
What i've got now is a placeholder, but that's actually an empty inputfield. So that's not what i'm looking for.
I'm looking for an (kind of) placeholder that's actually filled in into the input field, so not "background text"
This is with placeholder:
And this is what i want:
Is there any way to do this?

The value content attribute gives the default value of the input element.
- http://www.w3.org/TR/html5/forms.html#attr-input-value
To set the default value of an input element, use the value attribute.
<input type="text" value="default value">

All you have to do is use the value attribute of input tags:
<input type="text" value="Your Value" />
Or, in the case of a textarea:
<textarea>Your Value</textarea>

You seem to look for the input attribute value, "the initial value of the control"?
<input type="text" value="Morlodenhof 7" />
https://developer.mozilla.org/de/docs/Web/HTML/Element/Input#attr-value

<input type="text" value="Your value">
Use the value attribute for the pre filled in values.

TO give the prefill value in HTML Side as below:
HTML:
<input type="text" id="abc" value="any value">
JQUERY:
$(document).ready(function ()
{
$("#abc").val('any value');
});

Related

Bad value number for attribute value on element input

I am getting this error "Bad value number for attribute value on element input: Expected a minus sign or a digit but saw n instead" for this HTML code <label for='Card_Number'>Card Number:</label> <input type='number' id='Card_Number' name='Input_card_number' value='number' placeholder='0000-0000-0000-0000'>. Please how do i go about this?
You have an input with type=number but then you set the value to a string, here: value=number. I believe what you want to do is:
<label ...>...</label>
<input type='text' id'Card_Number' ... placeholder='0000-0000-0000-0000' />
and then think about using pattern or have type number, but then no - in your input

How do I show text in text field?

I used <s:iterator> tag to display checkboxs and text fields:
<s:iterator value="paramMapSimple" var="param" status="iteratorStatus">
<tr>
<td>
<input type="checkbox" name="params" key_id="<s:property value="#iteratorStatus.index "/>" value = "<s:property value="#param.key "/>"
<s:iterator value="params" var="app">
<s:if test="#app.substring(0,1)==#param.key">
checked
</s:if>
</s:iterator>/>
</td>
<td>
<input type="text" text_id="<s:property value="#iteratorStatus.index "/>" >
</td>
</tr>
params of type String[] stores the index and input text which have been checked, e.g., if the first and second checkboxes are checked, and the user input "paramName1" and "paramName2" in the text field, respectively, then params is: {1#paramName1, 2#paramName2}, and if the user check a checkbox but doesn't input anything, then default value will be stored, e.g., if the first and second checkboxes are checked, and the user only input "paramName1" for the first checkbox, then params is: {1#paramName1, 2#defaultParamName2}.
What I want is: if a checkbox is checked, then the text field shows the text input by the user (if the user doesn't input, shows the default value), otherwise, shows the default value.
In HTML, you can actually use a textarea:
For example:
<textarea rows="4" cols="50">
The text you want to put here!
</textarea>
You can refer to HTML textarea tag
You can also use a placeholder:
For example:
<form action="submit.php">
<label for="phone">Enter a phone number:</label><br><br>
<input type="tel" id="phone" name="phone" placeholder="123-45-678"
pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}"><br><br>
<small>Format: 123-45-678</small><br><br>
<input type="submit">
</form>
This will generate a hint text in the textbox!
You can refer more at HTML input placeholder

html how do I make required fields in forms [duplicate]

This question already has answers here:
How do I make a field required in HTML?
(16 answers)
Closed 2 months ago.
Is there any way i could make fields required. I tried the using required="required" in the input tag, but it still did not work. is there any other way?
<input name="Forename" type="text" required="required" id="Forename2" onkeyup="allLetter(this)"/>
you can add required to your input field, so it can be :
<input name="Forename" type="text" id="Forename2" onkeyup="allLetter(this)" required />
Hope this will help you :)
The required attribute can simply be included like this:
<input required>
So in your case, remove the attribute tag:
<input name="Forename" type="text" required id="Forename2" onkeyup="allLetter(this)"/>
In order to make required attribute work you should wrap your inputs into <form> tag. After that onSubmit event will give you behavior you expected.
You can try something like this:
function validate() {
var value = document.getElementById("myfield").value;
//make what you want
console.log(value);
}
<form >
<label>
your field: <input type="text" id="myfield" name="my_field" required onkeyup="validate()">
<input type="submit">
</label>
</form>

Validation | required="true" / "false" | HTML form

While I was doing some basic HTML I was wondering why Sublime Text 3 always completes required into required="" . Like my Instructor in an online course said it is not necessary to set required="true" or required="false" but when I set it to false it still requires it.
example code (it will require the field even if it is set tofalse):
<form>
<input type="password" name="password" required="false">
<button>Submit</button>
</form>
I hope you can clear up the confusion. Thanks for every answer.
Farcher
In HTML, the required attribute must be present (the field is required) or absent (the field is NOT required). When the attribute is present, it does not matter what value it has.
The required attribute is a boolean attribute. When specified, the element is required.
The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
About boolean attributes:
A boolean attribute without a value assigned to it (e.g. checked) is implicitly equivalent to one that has the empty string assigned to it (i.e. checked=""). As a consequence, it represents the true value.
The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.
A common practice is to use the name of the attribute as its value:
<form>
<input type="password" name="password" required="required"><!-- this input is required -->
<input type="text" name="sometext"><!-- this input is NOT required -->
<button>Submit</button>
</form>
'Required' is a Boolean attribute. It assumes the value of true once it is present. therefore setting it to a 'false' still makes it act as though it was true.
Below is proof
<form>
<input type="password" name="password" required="false">
<button>Submit</button>
</form>
required doesn't take a boolean string. It's required if the attribute exists at all. Sublime is likely expecting some value like most attributes.
<form>
<input type="password" name="password" required="">
<button>Submit</button>
</form>
<form>
<input type="password" name="password" required>
<button>Submit</button>
</form>
However, if one is handling mouse events, for instance, using JS, they can set the "required" attribute to "True" or "False" using the ".prop()" method. e.g.
.prop("required", true)
OR
.prop("required", false)

HTML input field hint

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>