0

I'm using javascript (backbone) to fill out an HTML form template. The form is an edit form, so it will be populated with existing values.

Unfortunately, when I browse to the form, values for a text input are getting truncated. For example, say the value of the field should be populated with "hello world" - but the form only shows the word before the space (hello) and the actual source looks like this (notice it thinks world is an attribute):

<input type="text" name="name" id="name" value="hello" world="">`

I'm not a huge HTML/Javascript expert. Does anyone know how I can escape the input?

Here's the template text that generates that form:

I'm not a huge HTML/Javascript expert. Does anyone know how I can escape the input?

Here's the template text that generates that form:

 <h1>Edit activity</h1>
  <form id="edit-activity" name="activity">
   <div class="field">
    <label for="name"> name:</label>
    <input type="text" name="name" id="name" value=<%= name %> >
   </div>
   <div class="actions">
     <input type="submit" value="Update Activity" />
   </div>
  </form>
  <a href="#/index">Back</a>
2
  • Can you please show us the view where you are working with this <input>? Commented Dec 17, 2011 at 16:38
  • not sure what you're asking here... do you want to see the html form? Commented Dec 17, 2011 at 16:46

1 Answer 1

1
<input type="text" name="name" id="name" value=<%= name %> >

Your problem is here. Try this instead

<input type="text" name="name" id="name" value="<%= name %>" >

What's happening is you are basically making this markup:

<input type="text" name="name" id="name" value=hello world >

Without the "s, the browser is interpreting the world value as an attribute. Placing the quotes in there does not adversely affect it, and when you think about it, it makes sense why it would work that way.

Sign up to request clarification or add additional context in comments.

1 Comment

@DanielD You're welcome :) happened to me too just recently :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.