0

In my javascript file, i have a variable that saves a name. I also have a html template where i am rendering that name as a value in an input field. This works fine if the value is one word, but anymore than one, it gets split up.

See screenshot for example. in the example i have a value of 'new house' which is being passed in via javascript. However it has been split up. When i debug, the name that is being passed through is correct ("new house") So i'm not sure how to keep it from splitting up

enter image description here

'<td>',
'<input value=<%= name %>></input>',
'</td>',
b.herring
  • 563
  • 2
  • 18
  • 3
    Actually, nothing test split up. The DOM you're seeing in the inspector section of your dev tools is an autocorrected DOM, not the actual source you're setting. Use `view-source` to see what you really did (namely, you didn't add quotes, so `new house` becomes `` and yeah, obviously that results in what you're seeing =) – Mike 'Pomax' Kamermans May 21 '20 at 16:30
  • ah yeah the quotes were the problem. Thank you – b.herring May 21 '20 at 16:34
  • `''` ??? – MoloF May 21 '20 at 16:37

1 Answers1

0

You need to add quotes to the value of the value attribute:

'<td>',
'<input value="<%= name %>"></input>',
'</td>',
Philipp
  • 10,240
  • 8
  • 59
  • 71