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
How to Check If Mod_Rewrite Is Enabled in PHP
Why Is MySQLi Giving a "Commands Out of Sync" Error
PHP 5.4 Call-time pass-by-reference - Easy Fix Available
How to Declare a Global Variable in PHP
Using Sessions & Session Variables in a PHP Login Script
Checking If Form Has Been Submitted - PHP
Why Is Require_Once So Bad to Use
Calling Non-Static Method With Double-Colon(::)
PHP Exec Command (Or Similar) to Not Wait For Result
PHP Warning: PHP Startup: How to Load Dynamic Library
Get All Permutations of a PHP Array
How to Use Shell_Exec Without Waiting For the Command to Complete
Remove Excess Whitespace from Within a String
How to Get the Base Url With PHP