What Values How to Put in an HTML Attribute Value

What values can I put in an HTML attribute value?

If your attribute value is quoted (starts and ends with double quotes "), then any characters except for double quotes and ampersands are allowed, which must be quoted as " and & respectively (or the equivalent numeric entity references, " and &)

You can also use single quotes around an attribute value. If you do this, you may use literal double quotes within the attribute: <span title='This is a "good" title.'>...</span>. In order to escape single quotes within such an attribute value, you must use the numeric entity reference ' since some browsers don't support the named entity, ' (which was not defined in HTML 4.01).

Furthermore, you can also create attributes with no quotes, but that restricts the set of characters you can have within it much further, disallowing the use of spaces, =, ', ", <, >, ` in the attribute.

See the HTML5 spec for more details.

what characters are allowed in the value attribute of form's input

HTML 5

Except where otherwise specified, attributes on HTML elements may have any string value, including the empty string. Except where explicitly stated, there is no restriction on what text can be specified in such attributes.

HTML 5

The value content attribute gives the default value of the input element. When the value content attribute is added, set, or removed, if the control's dirty value flag is false, the user agent must set the value of the element to the value of the value content attribute, if there is one, or the empty string otherwise, and then run the current value sanitization algorithm, if one is defined.

So there are no restrictions but the value might get altered by the value sanitization algorithm.


For instance, if I enclose this attribute in single close, I can not safely use single quotes in it.

You can. You just can't use literal single quotes. You have to use character references.

How can I enter multiple values for the html attribute value = val1, val2?

If all you're looking for is an array of values then you can separate them into multiple inputs with array-specified names. For example:

<input name="test[]" value="1">
<input name="test[]" value="2">
<input name="test[]" value="3">

When posted to the server $_POST['test'] would be an array with these three values.

If you want something more complex that is also possible, but perhaps not in the way you're thinking. The value of any given <input> (or <button>, etc.) is a string. Which means:

  1. You can put any string you want in there
  2. The code sees it as a string, just like any other string

That string can contain delimeted values:

<input value="one,two,three">

It can contain JSON (which would have to be HTML-encoded):

<input value="[{"id":"1"}]">

It can contain any string you like.

What you do with that string is what matters. For example, if a delimeted string is posted to the server then you can explode() that string into its values. Or if a JSON string is posted to the server then you can json_decode() that string into its data structure. (You may need to html_entity_decode() it first, that's worth testing.)

It's a string like any other, you can parse it like any other.

html attribute value to be passed as an argument for a javascript function

You need to define an id for the input. and pass the id through onclick, like:

<input type = "number" name = "bidAmount" id= "bid-amount" placeholder = "Bid Amount" required >

<button type="button" onclick="placeBid('bid-amount')">Submit</button>

and get the value with javascript inside your function:

<script>
function placeBid(id){
var value = document.getElementById(id).value;
...
}
</script>

what is data-info in html?

data-* attribute in HTML stores custom values. This stored data can be retrieved in JavaScript. In your case, data-info is the attribute name and its value is f:msnallexpuser,muiflt13cf. Value can be retrieved using getAttribute function in JavaScript.



Related Topics



Leave a reply



Submit