/    Sign up×
Community /Pin to ProfileBookmark

How to display a text and javascript value using document.write()

Hi Folks,

Actually, I want to display a javascript value in document.write() …. pls have a look at the following piece of code….
—————————————

<script language = “javascript”>

var a=6;

document.write(“<div class=’page_text’> your score is :</div>”);

document.write(“<h1>” + a + “</h>”);

</script>

When I use the above code the output is like

your score is : —————(long gap between the text and number) [B] 6[/B]

But I dont want to have a gap between the text and number. How can i remove the gap and make the text and number bring closer like this…

your socre is : 6

Eagerly waiting for your valuable replies…..

Thanks,
Suresh.H.V.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@mjdamatoDec 18.2006 — YOur problem is not Javascript - it is HTML. The Header tags <H1>, <H2>, etc. have default linebreaks and padding around them. You can either change the default styles in yout style sheets, or create a custom class and use span tags around the score with that class.
Copy linkTweet thisAlerts:
@bathurst_guyDec 18.2006 — well you placed the result in a h1 which will make it do that.

document.write("<div class='page_text'> your score is : "+a+"</div>");
Copy linkTweet thisAlerts:
@coppocksDec 18.2006 — Get rid of the <H1> tag and use a class with a large font inside a <span>...

Sample Class...
<i>
</i>&lt;style type="text/css"&gt;
.BigFont{

<i> </i>font-family:Verdana, Arial, Helvetica, sans-serif;
<i> </i>font-size:20pt;
<i> </i>color:#000;
}
&lt;/style&gt;

Revised JavaScript:
<i>
</i>&lt;script type="text/javascript"&gt;
var a=6;
document.write("&lt;div class='page_text'&gt; your score is : ");
document.write("&lt;span class='BigFont'&gt;" + a + "&lt;/span&gt;&lt;/div&gt;");
&lt;/script&gt;
Copy linkTweet thisAlerts:
@suresh_hvauthorDec 18.2006 — Hi Guys,

GR8 !!!!!!!!!!!!!!!!1

Thanks a lot, It works out now.....
Copy linkTweet thisAlerts:
@suresh_hvauthorDec 18.2006 — Hi Coppocks,

I am having another query.....

document.write("<span class='BigFont'>" + a + "</span></div>");

in the above mentioned line, the "BigFont" class is not getting assigned to the text.... Can you tell me why the css effect is not applied to the text???

Thanks.

Suresh.H.V.
Copy linkTweet thisAlerts:
@coppocksDec 18.2006 — Did you place the style in your header?

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test&lt;/title&gt;
&lt;style type="text/css"&gt;
.BigFont{

<i> </i>font-family:Verdana, Arial, Helvetica, sans-serif;
<i> </i>font-size:20pt;
<i> </i>color:#000;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script type="text/javascript"&gt;
var a=6;
document.write("&lt;div class='page_text'&gt; your score is : ");
document.write("&lt;span class='BigFont'&gt;" + a + "&lt;/span&gt;&lt;/div&gt;");
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;


I Tested in IE and FireFox.
×

Success!

Help @suresh_hv 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,
)...