Question: Pre-Populate form elements in EJS

Question

Pre-Populate form elements in EJS

Answers 0
Added at 2016-12-19 19:12
Tags
Question

I am sending information from a data base to the updatecontact.ejs. What this is doing is allowing the user to change the information they have already put in. So i would like to have the text forms already pre-populated with the users previous information. In the form itself to check that everything was sent over properly i printed everything out like this.

        <% var string = contacts[0].Street %>
        <p><%= contacts[0].Mr %> </p>
        <p><%= contacts[0].First %> </p>
        <p><%= contacts[0].Last %> </p>
        <p><%= contacts[0].Street %> </p>
        <p><%= contacts[0].City %> </p>
        <p><%= contacts[0].State %> </p>
        <p><%= contacts[0].Zip %> </p>
        <p><%= contacts[0].Phone %> </p>
        <p><%= string %> </p>

Everything prints out correctly. So if the Street was 55 Green Street it print it out. But when i go to pre-populate the text field it only shows the 55.

<label for="Street">Street:</label>
<input type="text" name ="Street" value = <%=contacts[0].Street  %>  required/>

How would i get it to print out 55 Green Street in the text field instead of just 55?

Answers to

Pre-Populate form elements in EJS

Source Show
◀ Wstecz