Reputation: 1656
I am appending input type using java script. but it is removing content after blank space
Java script code is
var temp = '<input type="hidden" name="nearest[]" id="nearest" value='+distance+'_'+location+'>';
$('#nearest_div').append(temp);
<div id="nearest_div"></div>
But if variable location is having space in name then it dont get append properly for eg if location = United States then it appends United only and ignores content after space
Upvotes: 0
Views: 111
Reputation: 6073
You didn't quote Value
, that's why it is not working.
For example if the value is "The United States of America", your code will produce a tag like this:
<input type="hidden" name="nearest[]" id="nearest" value=The United States>
but it should be:
<input type="hidden" name="nearest[]" id="nearest" value="The United States">
I changed your code:
var temp = '<input type="hidden" name="nearest[]" id="nearest" value="'+distance+'_'+location+'>"';
$('#nearest_div').append(temp);
Upvotes: 4