Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing without comboboxes 4

Status
Not open for further replies.

zishan619

Programmer
May 28, 2003
284
MX
I need to know how to print without the comboboxes. I would like to hide the comboboxes when printing. Is this possible.
Thanks
Z
Happy Holidays!!
 
My suggestion would be to create a "Printable Version" of your page without the combo boxes. The users would then click the "Printable Version" link when they wish to print.

-Ron

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
You can have different stylesheets for different medium. The media="" within style or link tag specifies in which medium specific stylesheet will be used. From then you can make two stylesheets, where one has select { display: none; } or something similar.
Code:
<link rel=&quot;stylesheet&quot; href=&quot;screenfile.css&quot;  type=&quot;text/css&quot; title=&quot;small&quot; media=&quot;screen&quot; />
<link rel=&quot;stylesheet&quot; href=&quot;printfile.css&quot;  type=&quot;text/css&quot; title=&quot;small&quot; media=&quot;print&quot; />
 
Sure :) It's all done with JavaScript. You'll need to create a print button on your page, that calls the print function bellow:

Code:
<script>
    function print_page()
    {
        var objForm = document.thisForm;  //where thisForm is the name of your form
        for (var i=0; i<objForm.elements.length; i++) //loop through all form elements
        {
            if (objForm.elements[i].type == &quot;select-one&quot;) //check if element is drop-down
            {
                objForm.elements[i].style.visibility = &quot;hidden&quot;;   //hide the drop down
            }
        }
        window.print();   //print the page
        for (var i=0; i<objForm.elements.length; i++) //loop through all form elements
        {
            if (objForm.elements[i].type == &quot;select-one&quot;) //check if element is drop down
            {
                objForm.elements[i].style.visibility = &quot;show&quot;; //make element visible again
            }
        }
    }
</script>

That should do the trick :). Good luck!

Take Care,
Mike
 
Vragabond: Good tip! I didn't know that was possible.

MichaelBronner: Good code. It's nice when others are willing to share their hard work so that other don't needlessly toil for hours. Thanks.

A STAR FOR BOTH!!

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
Vragabond: a star from me as well, nice tip! Didn't know that either :).

Take Care,
Mike
 
Hi Thank you very much. I place this code down like this
Response.Write &quot;<INPUT TYPE='BUTTON' Name='btnPrint' ID='btnPrint' VALUE='Print'>&quot; & vbcrlf

function print_page()
{
var objForm = document.frmZero
for (var i=0; i<objForm.elements.length; i++)
{
if (objForm.elements.type == &quot;select-one&quot;)
{
objForm.elements.style.visibility = &quot;hidden&quot;;
}
}
window.print(); //print the page
for (var i=0; i<objForm.elements.length; i++)
{
if (objForm.elements.type == &quot;select-one&quot;)
{
objForm.elements.style.visibility = &quot;show&quot;;
}
}
}
End Function
I keep getting an error on

for (var i=0; i<objForm.elements.length; i++)
Do I keep these } with the codes as well and the semicolons. Thanks
 
You need a semicolon after
Code:
var objForm = document.frmZero

That will fix it.

-Ron

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
Are you coding in ASP? Remember to escape ouot of ASP for this code.

you need to include the javascript in your page <head> tags, and enclose the function in <script> tags. Also, you need to call teh function when the button is pressed:

Code:
<INPUT TYPE='BUTTON' Name='btnPrint' ID='btnPrint' VALUE='Print' onlcick='print_page();'>

Take Care,
Mike
 
Hey I think it works except I got an error on
objForm.elements.style.visibility = &quot;show&quot;;
It states that it could not get the visibility property Invalid arguement. How can I fix this. Thanks
 
Also How do you hide buttons as well? Is there a website for the types that I can learn thanks
 
If you want to hide buttons, change
Code:
if (objForm.elements[i].type == &quot;select-one&quot;)
to this:
Code:
if ((objForm.elements[i].type == &quot;select-one&quot;) || (objForm.elements[i].type == &quot;button&quot;))

A good place for javascript reference is
Regarding the error: I don't see why it's giving you one, it shouldn't be...

Take Care,
Mike
 
This is the best print job function. Thank you very much to everyone.
I do have one more question How do I substitue a value from the dropdown boxes when the combo box hides itself so that the person knows what they selected to run the report?
Thanks
Happy Holidays.
 
Code:
<script>
    function print_page()
    {
        var objForm = document.thisForm;  //where thisForm is the name of your form
        for (var i=0; i<objForm.elements.length; i++) //loop through all form elements
        {
            if ((objForm.elements[i].type == &quot;select-one&quot;) || (objForm.elements[i].type == &quot;button&quot;)) //check if element is drop down or button
            {
                objForm.elements[i].style.visibility = &quot;hidden&quot;;   //hide the button
                if (objForm.elements[i].type == &quot;select-one&quot;)
                {
                    objForm.elements[i].parentNode.innerHTML += objForm.elements[i].value; //add the text
                }
            }
        }
        window.print();   //print the page
        for (var i=0; i<objForm.elements.length; i++) //loop through all form elements
        {
            if ((objForm.elements[i].type == &quot;select-one&quot;) || (objForm.elements[i].type == &quot;button&quot;)) //check if element is drop down
            {
                objForm.elements[i].style.visibility = &quot;show&quot;; //make element visible again
                if (objForm.elements[i].type == &quot;select-one&quot;)
                {
                    objForm.elements[i].parentNode.innerHTML = objForm.elements[i].parentNode.innerHTML.substr(0, (objForm.elements[i].parentNode.innerHTML.length - objForm.elements[i].value.length)); //take the text out
                }
            }
        }
    }
</script>

Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top