LDro
LDro

Reputation: 37

Adding saved variable data to an edit form with Jquery

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!

Upvotes: 1

Views: 319

Answers (1)

Ravinder Gujiri
Ravinder Gujiri

Reputation: 1514

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

$('.selector').val($('.selector').val());

Upvotes: 1

Related Questions