Print forms

J

Jason

Hello,

I am working on a website which uses forms to fill in a few answers to
questions. Does anybody know a javascript that prints only the answers
(i.e. the forms) and not the whole page?

I am asking this because printing the whole page takes 3 pieces of
paper, whilst printing only the answers will only take one.

Thank you.

Jason
 
S

Stuart Palmer

I have seen instances where onsubmit the form, it opens a small popup window
i a location off the visual screen size and this popup has a page in it with
the answers, this runs window.print onload, then after that runs
window.close. Thus prinitng the page and then closing it.

Would that do/sould like what you want to do?

Stu
 
J

Jason

That would be great! Can you help me with this script? I am quite a
novice into javascript coding, so I could use a little help.

Thanks,

Jason
 
V

Vicomte De Valmont

ciao
well it can be achieved in a variety of ways. I don't know precisely how
your page is arranged, and thus I can make only a few suggestions, not
necessarily the best ones, yet functional and they could be more precise
knowing better your pages.
Your 'problem' is basically to isolate a few form fields. let's say they are
input type="text" fields. Say your form has a name: "myform". This goes (or
must be called) after the form has loaded (arguably, you'll nest it within a
function, returning the output)

var output="";
var theform=document.myform;
for(var i=0; i<theform.length; i++){
if(theform.elements.type=="text"){
output+=theform.elements.value+"<br>";
}
}
alert(output);/*in a function: return output; to write document wriote or
whatever depending on where you print, maybe a textarea I have no clue*/

I hope this is what you meant. if you know beforehand the names of the form
fields involved, or they are arranged so that only a suffix chages, we can
even arrange faster loops, if that is of any concern for you.
ciao
Alberto Vallini
http://www.unitedscripters.com/
 
J

Jason

Hi Alberto,

Thank you for your reply.

Since I am not very much known with javascript coding/syntax, would it
be an idea if I send you a copy of the webpage, so you can have a
closer look to it? If you agree, please send your email address to
(e-mail address removed)

Thanks,

Jason French

Vicomte De Valmont said:
ciao
well it can be achieved in a variety of ways. I don't know precisely how
your page is arranged, and thus I can make only a few suggestions, not
necessarily the best ones, yet functional and they could be more precise
knowing better your pages.
Your 'problem' is basically to isolate a few form fields. let's say they are
input type="text" fields. Say your form has a name: "myform". This goes (or
must be called) after the form has loaded (arguably, you'll nest it within a
function, returning the output)

var output="";
var theform=document.myform;
for(var i=0; i<theform.length; i++){
if(theform.elements.type=="text"){
output+=theform.elements.value+"<br>";
}
}
alert(output);/*in a function: return output; to write document wriote or
whatever depending on where you print, maybe a textarea I have no clue*/

I hope this is what you meant. if you know beforehand the names of the form
fields involved, or they are arranged so that only a suffix chages, we can
even arrange faster loops, if that is of any concern for you.
ciao
Alberto Vallini
http://www.unitedscripters.com/





Jason said:
Hello,

I am working on a website which uses forms to fill in a few answers to
questions. Does anybody know a javascript that prints only the answers
(i.e. the forms) and not the whole page?

I am asking this because printing the whole page takes 3 pieces of
paper, whilst printing only the answers will only take one.

Thank you.

Jason
 
V

Vicomte De Valmont

ciao jason,

well post it here, if it is not too long. yet you can reiterate all the
elements in a form in the way I previously stated so if you do that, you'll
achieve your result. It's simpler that you may think. if you're new at js as
you say the best way to learn is to just try coding - never mind of mistkes,
everybody makes it and you can find everyday expert programmers that are
liable to the silliest mistakes like forgetting a dot, an escape char, or a
comma. That's just normal, human. Don't worry. if they say to you they have
achieved a point where they don't make silly mistakes anymore any longer
don't believe it :) We all make mistakes, and it is exactly by making
mistakes that you can get proficiency.
try that code. make a snippet form with 2 or 3 fields and then run it (of
course be sure the name of the form matches)
ciao
Alberto
var output="";
var theform=document.myform;
for(var i=0; i<theform.length; i++){
if(theform.elements.type=="text"){
output+=theform.elements.value+"<br>";
}
}
alert(output);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top