1

I have the following html form saved to the following Javascript variables using jquery...

<form>
<input id="name" type="text" placeholder="Name">
<input id="phone" type="text" placeholder="Phone Number">
<input id="email" type="text" placeholder="E-mail">
<input id="image" type="text" placeholder="Image URL">
<button id="submit">Submit</button>

$('input').keypress(function(e){
    if(e.which == 13){
        e.preventDefault();
        var name = $('#name').val();
        var phone = $('#phone').val();
        var email = $('#email').val();
        var image = $('#image').val();
        addContact(name,phone,email,image);
    }; 
});

I'd like to be able to repopulate another similar form with the variable data populated for editing purposes at the bottom of my page using Jquery, but I am unclear on how to do so using Jquery. I thought could append the variable values to my new form by calling .html and appendTo, but continue to run into trouble. Any insight is much appreciated.

Thanks!

2
  • Use val() instead of append, $('#othername').val(name); Commented May 20, 2014 at 5:08
  • use class selector's instead of id's and simple $('.selector').val($('.selector').val()); Commented May 20, 2014 at 5:09

1 Answer 1

1

use class selector's instead of id's and simple

$('.selector').val($('.selector').val());
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.