Jaikrat
Jaikrat

Reputation: 1154

How to get all the Form elements, with values, in a popup window

I have one functionality to get the print of current page. So to prepare the content, I am showing everything on one popup up first then later a print popup and then print command.

Trying to do the same with below code.

$('#button').on('click',function() { 
    var popup = window.open("","mypopup","width=500,height=300");
     var html = $("#form").html();
    $(popup.document.body).html(html);
    popup.print();
});

Image of output

JSFiddle

Tried with clone() method as well but not working.

So the issue is, I am not getting the element's values in my popup.

Thanks

Upvotes: 0

Views: 1970

Answers (2)

krunal nanda
krunal nanda

Reputation: 235

HI Use simple jquery line for each input field.

You can add a value attribute for your input fields.

I have changed your script a bit. Please refer it.

$('#button').on('click',function() { 
    var popup = window.open("","mypopup","width=500,height=300");
// I am setting the value attribute in the html . Do this for all fields
// with similar input fields you can have a jQuery('input').each(); loop
    $('#name').attr('value',$('#name').val());

    var html = $("#form").html();
    $(popup.document.body).html(html);
    popup.print();
}); 

Upvotes: 3

Vignesh
Vignesh

Reputation: 99

Manually send the data from form through ajax call and store it in a local websql (browser)storage which can be retrived in the print preview dialog box

Upvotes: 0

Related Questions