1

Below is my simple form html where I want to add the object data to my form fields. I went through Google search and StackOverflow but all of them were talking about jquery implementation, so here is my simple form html where I want to add the object data to my form fields. Since I'm not aware of Jquery, I want to use the Java Script approach.

Below, I have a user form where I want to bind the details object to my above form fields, so for that I'm using the below java script approach. I don't know where I'm going wrong. My object data is not getting bound with my form.  So kindly help me with it. Thank you.

<!DOCTYPE html>
<html>
    <body>
        <div>
            <form>
                Name&nbsp<input id="name" type="text" name="name"><br>
                Place&nbsp<input id="place" type="text" name="place"><br>
                Age&nbsp<input id="age" type="text" name="age">  
            </form> 
        </div>
        <script>
            
            var details ={name:'Krishna',place:'India',age:26}; 
            
            document.getElementById("name").innerHTML=details.name;
            document.getElementById("place").innerHTML=details.palce;
            document.getElementById("age").innerHTML=details.age;
            
        </script>
    </body>
</html>
2
  • 1
    <input> tags do not have innerHTML, use .value instead Commented Jan 9, 2016 at 6:41
  • palce --> place, for one Commented Jan 9, 2016 at 6:41

1 Answer 1

1

As mentioned in the comment by @Jaromanda X, there is no innerHTML for an input field. Instead, you should try setting the value attribute.

    <script>
        var details ={name:'Krishna',place:'India',age:26}; 
        document.getElementById("name").value = details.name;
        document.getElementById("place").value = details.place;
        document.getElementById("age").value = details.age;
    </script>

This should do the trick.

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

Comments

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.