Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML in the input field value

Tags:

How can I get HTML to work in the value of the input field ? If you include HTML in the value, it appears as pure text. Is there a way to do something like this?

<input type='text' value='<b>tekst</b>'></input>

So the the output is:

tekst

instead of

<b>tekst</b>

I think that was bad example... I want every appropriate HTML tag to work. If i want to include an image, the image appears in the input, if i want to add a tag ... the text should appear as a link linked.

like image 786
weardstuff Avatar asked Apr 28 '11 19:04

weardstuff


People also ask

How can I get the value entered in the input field?

Answer: Use the value Property You can simply use the value property of the DOM input element to get the value of text input field.

What is input field in HTML?

The <input> tag specifies an input field where the user can enter data. The <input> element is the most important form element. The <input> element can be displayed in several ways, depending on the type attribute.

What is name and value in input HTML?

Value = The value attribute specifies the value of an element. Name = name is only to post form data. The name definies what the name of the attribute will be as soon as the form is submitted. So if you want to read this attribute later you will find it under the "name" in the POST or GET Request.


1 Answers

I'm not sure from your question whether you are trying to make the value contain HTML, or whether you want to apply HTML to something inside the input.

If you want to be able to set the value to some HTML, like <input value="<b>Some HTML</b>"> where the value will actually show the HTML, you need to encode the HTML brackets like <input value="&lt;b&gt;Some text&lt;b/&gt;">. There are functions available to do this for you automatically in most scripting languages (e.g. htmlentities() in PHP).

If you want to apply HTML to the input value, short answer is... you can't. If you want formatting on there, you could use the contentEditable attribute in HTML5 which lets you just edit-in-place (think Flickr headers).

If you just want a standard input field to be styled, you can just use CSS like the other answers suggested.

like image 192
Dan Blows Avatar answered Oct 06 '22 00:10

Dan Blows