0

I have a form of a prescription. I want to print out that prescription form while submit and also want a proper format in that printout page.

form html

<form role="form" class="registration-form" id="registration_form_id">
<fieldset>
    <div class="form-top">
        <div class="form-top-left">
            <h3>Patient Information</h3>
        </div>
        <div class="form-top-right">
            <i class="fa fa-user"></i>
        </div>
    </div>
    <div class="form-bottom">
        <div class="form-group">
            <label for="form-first-name">Name</label>
            <input type="text" name="form-first-name" placeholder="name" class="form-first-name form-control require" id="name">
        </div>
        <div class="form-group">
            <label for="form-last-name">Age</label>
            <input type="number" name="form-last-name" placeholder="Age" class="form-last-name form-control require" id="age" >
        </div>
        <div class="form-group">
            <label for="form-last-name">Mobile Number</label>
            <input type="number" name="form-last-name" placeholder="Mobile Number" class="form-last-name form-control require" id="mobile_number" >
        </div>
        <div class="form-group">
            <label for="form-last-name">Religion</label>
            <input type="text" name="form-last-name" placeholder="Religion" class="form-last-name form-control require" id="religion" >
        </div>
        <div class="form-group">
            <label for="form-last-name">Occupation</label>
            <input type="text" name="form-last-name" placeholder="Occupation" class="form-last-name form-control require" id="occupation" required>
        </div>
        <div class="form-group">
            <h4>Gender</h4>
            <div class="row">
                <div class="col-md-4">
                    Male<input class="col-md-4" type="radio" name="gender" value="1">
                </div>
                <div class="col-md-4">
                    Female<input class="col-md-4" type="radio" name="gender" value="2">
                </div>
                <div class="col-md-4">
                    Other<input class="col-md-4" type="radio" name="gender" value="3">
                </div>
            </div>
        </div>
        <div class="form-group">
            <h4>Marital status</h4>
            <div class="row">
                <div class="col-md-4">
                    Married<input type="radio" class="col-md-4" name="marital_status" value="1">
                </div>                                          
                <div class="col-md-4">
                    Single<input type="radio" name="marital_status" class="col-md-4" value="1">
                </div>
            </div>
        </div>            
        <button type="button" class="btn btn-next">Next</button>
    </div>
</fieldset>    
<fieldset>
    <div class="form-group">
        <label for="form-about-yourself">Allergic history</label>
        <textarea name="allergic_history" placeholder="Allergic history" class="form-about-yourself form-control " id="allergic_history" ></textarea>
    </div>
    <div class="form-group">
        <label for="form-about-yourself">Personal history</label>
        <textarea name="personal_history" placeholder="Personal history" class="form-about-yourself form-control " id="personal_history" ></textarea>
    </div>

    <button type="button" class="btn btn-previous">Previous</button>
    <button type="button" class="btn" id="prescription_form_submition">Submit!</button>
</fieldset>

printout code in js

var divToPrint = document.getElementById('registration_form_id');

            newWin= window.open("");

            newWin.document.write('<html><style>@media print{body {font-size:16px;} #patient_doctor_info{border-bottom:1px solid #ccc;overflow:hidden;padding:20px 0 10px 0;} #patient_doctor_info span{font-size:18px;} #patient_info{float:left;} #doctor_info{float:right;} #patient_prescription_info{padding:20px 0;overflow:hidden;} #patient_old_prescription{padding-right:5%;border-bottom:1px solid #000;} #patient_new_prescription{overflow:hidden;padding:0 20px;} .new_prescription{font-size : 20px}}</style><body onload="window.print()"><div id="patient_doctor_info"><div id="patient_info"><p><lable>Name :</lable><span><b>'+name+'</b></span></p><p><lable>Mobile Number :</lable><span><b>'+mobile_no+'</b></span></p><p><lable>Age :</lable><span><b>'+age+'</b></span></p><p><lable>Gender :</lable><span><b>'+sex+'</b></span></p></div><div id="patient_prescription_info"><div id="patient_old_prescription"><p><lable>Allergy :</lable><span><b>'+allergic_history+'</b></span></p><p><lable>Social History :</lable><span><b>'+personal_history+'</b></span></p></div></div></body></html>');

            newWin.print();
            newWin.close();

the print pagelooks like the below image enter image description here

But I want like below image enter image description here

So my main questions are.....

  1. how to printout specific div or form value of a webpage using javascript.

  2. How to apply css in that print page?

I have googling this issue several times but still not getting proper solution. Anybody help please ?

Arafat Rahman
  • 993
  • 5
  • 19
  • 46

0 Answers0