I am trying to add some CRUD functionality to my web app and I am having a little trouble conquering this tiny details.
I am pulling in some data from express into my EJS template. I have some form fields in a table I will make visible upon clicking the 'edit' button.
I want the data from corresponding row to auto-populate the form fields.
As of now, only the first word is being populated into the field, but the remaining words are being excluded.
Here is the EJS.
<% if (expenses.length > 0) { %>
<table>
<tr>
<th>Category</th>
<th>Date</th>
<th>Place</th>
<th>Description</th>
<th>Price</th>
<th>Edit</th>
</tr>
<% expenses.forEach(expense => { %>
<tr>
<td><%=expense.category%></td>
<td><%=expense.date%></td>
<td><%=expense.place%></td>
<td><%=expense.description%></td>
<td><%=expense.price%></td>
<td>
<button>Edit</button>
</td>
</tr>
<tr>
<form action=<%="/expense/updateExpense/" + invoice._id%>>
<td>
<select name="expense_category" id="expense_category">
<option value=<%=expense.category%>></option>
<% categories.forEach(category => { %>
<option value=<%=category.name%>><%=category.name%></option>
<% }) %>
</select>
</td>
<td>
<input type="text" name="expense_date" value=<%=expense.date%>>
</td>
<td>
<input type="text" name="expense_place" value=<%=expense.place%>>
</td>
<td>
<input type="text" name="expense_description" value=<%=expense.description%>>
</td>
<td>
<input type="text" name="expense_price" value=<%=expense.price%>>
</td>
</form>
</tr>
<% }) %>
</table>
<% } %>
Now lets zoom in on a specific row I am talking about
<td>
<input type="text" name="expense_place" value=<%=expense.place%>>
</td>
The value of 'expense.place' should read, "Sam's Club" but only the word "Sam's" is being populated into the input field.
I have tried doing expense.place.split(' ')
but this returns "Sam's,Club"
and then I tried doing expense.place.split(' ').join(' ')
and it just returns Sam's
.
Does anybody have any advice for me on this one?