/    Sign up×
Community /Pin to ProfileBookmark

out.write’ing into input fields for emailing?

This should be pretty straightforward, but I don’t see it…

I have an existing quiz in js that nicely writes a results page, from values stored in a cookie. I want to provide a way to email the quiz results (from the cookie) to an addressee from either a free-text email or a dropdown list of email addresses.

How can I modify this for the follow-on desire to email the results:

[code=php]// Function to print quiz question results
// out – Document output reference
// prob – Number of problem
// total – Total # of possible correct answers
// returns – Number of correct answers for this problem
function printQuizInfo(out, prob, total) {
var ques, correctAns, wrongAns, percent;
var cookie = “q” + prob;

out.write(“<TR>n <TD align=”left”>” + prob + “n” +
” <TD align=”center”>”);

correctAns = parseInt(getSubValue(“ans”, cookie));
out.write(correctAns + “n <TD align=”center”>”);

wrongAns = total – correctAns;
out.write(wrongAns + “n <TD align=”right”>”);

percent = Math.round((correctAns / total) * 100);
printPercent(out, percent);

return correctAns;
}

// Function to print quiz totals
// out – Document output reference
// total – Total # of questions in quiz
// right – # of questions answered right
function printQuizTotal(out, total, right) {
var percent;

out.write(“<TR>n <TH align=”left”>Totaln <TD align=”center”>”);
out.writeln(right);

out.write(” <TD align=”center”>”);
out.writeln(total-right);

out.write(” <TD align=”right”>”);
percent = Math.round((right / total) * 100);
printPercent(out, percent);
}[/code]

I think it should be easy enough to take these lines:

[code=php]out.write(“<TR>n <TD align=”left”>” + prob + “n” +
” <TD align=”center”>”);

correctAns = parseInt(getSubValue(“ans”, cookie));
out.write(correctAns + “n <TD align=”center”>”);

wrongAns = total – correctAns;
out.write(wrongAns + “n <TD align=”right”>”);

percent = Math.round((correctAns / total) * 100);
printPercent(out, percent);

return correctAns;
[/code]

and modify the table wrappers to turn the results into inputs on a form to submit to the email I want to send. But I don’t see quite how to include the input tags for correct rendering.

Like I said, this should be easy, but I’m totally not seeing it today.

Suggestions for starting points or some rough code snips very welcome.

-Spaz68
?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Spaz68 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...