Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i got many textarea how do i send them to print but only the full one if i got an empty one he doesn't print him


thanks for the help
Posted
Comments
Ishpreet Kaur 3-Dec-14 11:56am    
What you have tried so far? Where did you stuck?
Can you post some code whatever you have tried?
RedDk 3-Dec-14 13:40pm    
Often the outlook for printing HTML webpages is grim due to all the weirdness in panels that show in some browsers and fail to load in others. If a print of a page is all you need and you're not too sorry about Visual Studio being only 32-bit, then use VS to open that page in DESIGN mode. Then just DELETE everything that is grubby or not spot on.

Experiment.

You could try using css and javascript in conjunction to get your desired effect.
CSS
/*for print css - do not display textarea if it has a class of empty*/
@media print {
    textarea.empty{display:none;}
}

JavaScript
//test if textarea has value, during page start-up and onblur, add empty class to textarea if it is empty
$(document).ready(function (){
    $('textarea').each(function (i, e) {
        if (!$(e).val()) {
            $(e).addClass("empty");
        }

        $(e).bind("blur", function() {
            if (!$(this).val()) {
                $(this).addClass("empty");
            }
            else{
                $(this).removeClass("empty");
            }
        });
    });
});

If a container ancestor div is required to not be printed:
CSS
/*change the media print css to not display div*/
@media print {
    div.empty{display:none;}
}

JavaScript
//modify the javascript to point to the ancestor div
//do it for all addClass and removeClass
           //$(e).addClass("empty");
           $(this).parent("div").addClass("empty");
 
Share this answer
 
v2
Comments
jaket-cp 4-Dec-14 5:07am    
thanks :)
Mich1309 4-Dec-14 5:05am    
i like your solution but i have a small problem near all the textarea i have a label also if the textarea is empty i want that all the line will disappear
Mich1309 4-Dec-14 5:08am    
<div id='que_q5g2'>
<label>Text</label>
<textarea id='TXT_A1Q5G2' style='OVERFLOW: visible; TEXT-OVERFLOW: ellipsis; WORD-WRAP: break-word' name='TXTA1Q5G2' rows='1' cols='34' tabindex='2' ></textarea>
</div>
jaket-cp 4-Dec-14 5:28am    
I've modify solution, you should be able to figure it out from there.
If not, pop me another comment.
good coding :)
If you want to print only content of textarea, you may try this.

For more Information: Print Div Content Using JavaScript[^]
 
Share this answer
 
Check if the TextArea is empty or not. You can easily check with the help with JavaScript or jQuery.

Then if the TextArea is not empty after this check, the. Print that.

Demo


[Demo] Hide Empty TextAreas before Printing the Window[^]
 
Share this answer
 
v2
Comments
Mich1309 4-Dec-14 2:46am    
can show me an example please?
Did you try anything?
Mich1309 4-Dec-14 3:01am    
window.onbeforeprint = function () {
$.each("textarea", function (i, e) {
if (!$(e).val()) {
alert('123');
}
});
};



i want before the the print to hide all empty text area in the form
Don't use this Event as it is not supported by modern browsers. See my updated solution. I have included the demo. See how I have done this.
jaket-cp 4-Dec-14 4:58am    
I like your idea, very nice.
I have put in a solution to use css and javascript with your solution in mind.
Please take a look.
Also 5ed yours :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900