How to Set HTML Value Attribute (With Spaces)

How to set HTML value attribute (with spaces)

Quote it. Otherwise the space will just become an attribute separator and everything after spaces will be seen as element attributes. Rightclick page in webbrowser and view source. It should not look like this (also see syntax highlight colors):

<input value=Big Ted>

but rather this

<input value="Big Ted">

Not to mention that this would still break when someone has a quote in his name (and your code is thus sensitive to XSS attacks). Use htmlspecialchars().

Kickoff example:

<input value="<?php echo (isset($_POST['username']) ? htmlspecialchars($_POST['username']) : ''); ?>">

HTML Value attribute Ignores White space between Passed String

Try this:

<Input type="hidden" name="park_name" value='<%= nationalParks[k].nationalPark %>' /> 

instead of this:

 <Input type="hidden" name="park_name" value=<%= nationalParks[k].nationalPark %> />  

Missing HTML Attribute Value With Spaces from jQuery

Because you don't have quotes around the attribute values.

Your code is going to append:

<div className=COS 102 ...

when it should append

<div className='COS 102' ...

This should work:

<script>
var className = "COS 102";
var teacher = "Bob Teacher";

$("#classesDiv").append("<div className='"+className+"' teacher='"+teacher+"' class='class'></div>");
</script>

Spaces between html attributes and values?

Yes, any amount of whitespace is allowed and will work in all browsers.

One consideration - this will add to the page size, so if bandwidth and performance are concerns, try to limit the amount of whitespace you use.

Is there any issue with having spaces in an HTML checkboxes value attribute?

No, There's no problem having spaces on value attributes for checkboxes.

Reference: W3C - The value attribute is String type

issue about spaces between words in value attribute

You're missing quotes around the attribute:

var span = '<input type="radio" value="'+ ui.text +'"> ...

How to not hardcode HTML value attributes (with spaces) in R

Try

  template <- "
.option[data-value='%s'], .item[data-value='%s']{
background: %s !important;
color: white !important;
}"


Related Topics



Leave a reply



Submit