/    Sign up×
Community /Pin to ProfileBookmark

Weird stuff with change font family in document.write

Hi, folks!

When I send a form from html to a function in javascript via a button I want to write the values of the html form on the screen.

I do so by using the document.write() in javascript. This removes the page with the html form (input boxes etc) and then the only thing displayed is the stuff written by javascript. And the font family I had in the html part is now gone!
Only problem is that I want to change the font family (like Times New Roman, Arial Black etc).

How can this be done? ?

I have very many document.write()’s, so would be swell if there were something that made me change the entire script’s font family! ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@bionoidDec 20.2011 — When you use document.write, it removes all html including your references to stylesheets etc.

An easy fix would be to write a container element that defines some basic styling around your output:

[CODE]document.write(
'<div style="color: #00f; font-family: verdana, tahoma, arial, helvetica, sans-serif; font-size: small;">' +
'This is some example text, place what you intend on writing here.' +
'</div>'
);[/CODE]


If you have to do this in multiple places I would suggest then using a function, and calling that instead:

[CODE]function writeOutput(text)
{
document.write(
'<div style="color: blue; font-family: verdana, tahoma, arial, helvetica, sans-serif; font-size: small;">' +
text +
'</div>'
);
}

writeOutput('This is some example text, place what you intend on writing here.');[/CODE]
×

Success!

Help @Blekkulf 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...