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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing - hide items using javascript

Status
Not open for further replies.

andycape

Programmer
Aug 22, 2003
177
ZA
I get my user to choose a value from a drop down and then when Iprint the form, the value, not the select box appears.
To do this I use :

Code:
<span class="noPrint"><select style="width:150px;" name="Company">
	////  My select box is here
</select></span><div id="select"></div>


<script>
function PrintWin()
{
 document.getElementById("select").innerHTML= document.form.Company.options[document.form.Company.selectedIndex].value

 window.print()
}
</script>

So the value of the select box is printed.

My problem is now I want to do it with the select box and two text fields, but it is not working. Is it not possible to do the above, but to more than one field at a time ?

eg :

Code:
<span class="noPrint"><select style="width:150px;" name="Company">
	////  My select box is here
</select></span><div id="select"></div>

<span class="noPrint"><textarea cols="30" rows="5" name="Address" id="Address">Please fill in address here</textarea></span><div id="Address"></div>

<input type="text" name="Dear" style="width:200"></span><div id="Dear"></div>


<script>
function PrintWin()
{
 document.getElementById("select").innerHTML= document.form.Company.options[document.form.Company.selectedIndex].value
 document.getElementById("Address").innerHTML= document.form.Address.value 
 document.getElementById("Dear").innerHTML= document.form.Dear.value 
 window.print()
}
</script>

This is what I'm trying to use but none of the figures are printing.
 
No I'm not, you are probably looking at the address text box, sorry I typed that wrong I dont have an ID, just a name. The only ID's i have are the three divs - "select", "address" & "dear", where I want the information to be printed.
 
you are using select - you could be confusing the browser, it might be looking for a form element
 
I changed it to "sel" and I'm still getting nothing. i cant understand why it works with just the select box,but not when i add the text box's. am i refrensing them correctly ?

ie :
Code:
document.getElementById("Dear").innerHTML= document.form.Dear.value
 
Try changing the way you are referring to your form.

You currently have:

Code:
document.form.

You should use either:

Code:
document.forms[0].

(assuming you are talking about the first/only form on the page), or:

Code:
document.forms['formName'].

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top