Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / March 2006



Tip: Looking for answers? Try searching our database.

Printing in one line like in Java or C/C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jamiil - 30 Mar 2006 23:46 GMT
JavaScipt
~~~~~~~
     <script type="text/javascript">
       name = new String("My Name");
       document.write("<H4>Author: </H4>" + name);
     </script>

I would like the word 'Author:' to be in 4th level heading and the name
variable value to be displayed in regular font, I get that but in two
lines. What can I do to get the browser to display the two values in
one line?

TIA.
Vic Sowers - 31 Mar 2006 00:04 GMT
> JavaScipt
> ~~~~~~~
[quoted text clipped - 7 lines]
> lines. What can I do to get the browser to display the two values in
> one line?

The header elements are, by default, defined as 'block' elements, which
means they insert a line break following the element, so it's best not to
use them in this context.

Instead use a font control element like:

   document.write("<strong>Author: </strong>" + name);

or

   document.write("<span style='font:bold 12pt Arial;'">Author: </span>" +
name);

If you absolutely must use the <H4> element, try:

   document.write("<H4 style='display:inline;'">Author: </H4>" + name);
Thomas 'PointedEars' Lahn - 31 Mar 2006 00:32 GMT
> JavaScipt

What?

> ~~~~~~~
>       <script type="text/javascript">
>         name = new String("My Name");

You do not have to create a String object for this.  A string value will do
just fine.  Using `name' undeclared is overwriting the `name' property of
the global Window object in known HTML environments.  Declaring `name'
perhaps disables it.  Do not use `name' in global context.

 var ref = "My Name";

>         document.write("<H4>Author: </H4>" + name);

Must be

 document.write("<H4>Author: <\/H4>" + ref);

Should be

 document.write("<h4>Author: <\/h4>" + ref);

>       </script>
>
> I would like the word 'Author:' to be in 4th level heading and the name
> variable value to be displayed in regular font, I get that but in two
> lines. What can I do to get the browser to display the two values in
> one line?

This has nothing to do with programming in an ECMAScript-conforming language
(which is on-topic here).  Try CSS, and do not add whitespace at the end of
the element content:

 <h4 style="display:inline">Author:</h4>

Never ever use a hX element if it is not a heading, just because it looks
nice on your browser!  Use font-formatting instead.

<URL:http://www.w3.org/QA/Tips/headings>

PointedEars
Hal Rosser - 31 Mar 2006 01:53 GMT
> JavaScipt
> ~~~~~~~
[quoted text clipped - 7 lines]
> lines. What can I do to get the browser to display the two values in
> one line?

The h4 tag will show on its own line by default.
Why not use <p> and <span> tags with style attributes to get it to look the
way you want.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.