By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,481 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,481 IT Pros & Developers. It's quick & easy.

Write. function

P: n/a
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");
document.write("<font size 3 </font>");
document.write(myname);

}

does anyone know how I cn get the users name to appear on the same page
(without using text box)? Maybe it cant be done using javascript.

Thanks for your time

Cass27

Aug 31 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a
cass27 wrote on 31 aug 2006 in comp.lang.javascript:
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");
document.write("<font size 3 </font>");
document.write(myname);

}

does anyone know how I cn get the users name to appear on the same page
(without using text box)?
Yes.
Maybe it cant be done using javascript.
A bad start thinking that. ;-)

[We should not do your homework by writing your code.]

You cannot do a document.write() after the page is loaded without
destroying both the page AND THE EMBEDDED JAVASCRIPT!
Your second document.write() has gone when the interpreter reaches it.

Look into .innerHTML to put your string into an <divor <span>

Or, if you are up to it, use the DOM's childNode.

And do not use <fontnomore,
[you must have ancient course material!],
use css styles instead.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 31 '06 #2

P: n/a
cass27 wrote:
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");
document.write("<font size 3 </font>");
document.write(myname);

}

does anyone know how I cn get the users name to appear on the same
page (without using text box)? Maybe it cant be done using javascript.
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function getName() {
var myName = prompt("What is your name?","");
var usr = document.getElementById("userName");
usr.innerHTML = myName;
}
</script>
</head>

<body onLoad="getName();">
<p>Some text...</p>

<div style="font-size:large;">
Welcome <span id="userName"></span>
</div>

<p>Some more text...</p>
</body>

</html>
--
Dag.
Aug 31 '06 #3

P: n/a

cass27 wrote:
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.
Tip 1: after the page has finished loading, document.wirte first calls
document.open, which clears the current page before writing the new
content.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");
Tip 2: use a modern version of HTML. The font element was deprecated
in 1997 with HTML 4.0.
[...]
does anyone know how I cn get the users name to appear on the same page
(without using text box)? Maybe it cant be done using javascript.
Tip 3: learn about getElementById and how to change the value of a text
node.

Start with the FAQ:
<URL: http://www.jibbering.com/faq/#FAQ4_15 >

Continue at quirksmode:
<URL: http://www.quirksmode.org/ >
--
Rob

Aug 31 '06 #4

P: n/a
I shall consider myself told off. I think my course is a bit ancient.
And its only fundementals. For instance I had never heard of innerHTML.
What is this actually doing?

cass27
Evertjan. wrote:
cass27 wrote on 31 aug 2006 in comp.lang.javascript:
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");
document.write("<font size 3 </font>");
document.write(myname);

}

does anyone know how I cn get the users name to appear on the same page
(without using text box)?

Yes.
Maybe it cant be done using javascript.

A bad start thinking that. ;-)

[We should not do your homework by writing your code.]

You cannot do a document.write() after the page is loaded without
destroying both the page AND THE EMBEDDED JAVASCRIPT!
Your second document.write() has gone when the interpreter reaches it.

Look into .innerHTML to put your string into an <divor <span>

Or, if you are up to it, use the DOM's childNode.

And do not use <fontnomore,
[you must have ancient course material!],
use css styles instead.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 31 '06 #5

P: n/a
HI dag,
thanks for that. It works a treat. Im new to these groups and
javascript. My course is very fundemental and doesnt seem to cover tags
like usr.innerHTML. Im relising there are a lot of properties, objects
and methods etc, I am not aware of. Is there a glossary anywhere of
terms which can be used?

Cass27
Dag Sunde wrote:
cass27 wrote:
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");
document.write("<font size 3 </font>");
document.write(myname);

}

does anyone know how I cn get the users name to appear on the same
page (without using text box)? Maybe it cant be done using javascript.
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function getName() {
var myName = prompt("What is your name?","");
var usr = document.getElementById("userName");
usr.innerHTML = myName;
}
</script>
</head>

<body onLoad="getName();">
<p>Some text...</p>

<div style="font-size:large;">
Welcome <span id="userName"></span>
</div>

<p>Some more text...</p>
</body>

</html>
--
Dag.
Aug 31 '06 #6

P: n/a
cass27 wrote on 31 aug 2006 in comp.lang.javascript:
I shall consider myself told off. I think my course is a bit ancient.
And its only fundementals. For instance I had never heard of innerHTML.
What is this actually doing?
[please do not toppost on usenet]

Read the many online tutorials:

http://google.com/search?q=tutorial+javascript

and even before that this newsgoup's FAQs:

<http://www.jibbering.com/faq/>

and

<http://www.merlyn.demon.co.uk/js-index.htm>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 31 '06 #7

P: n/a
Thanx for your help. I will definately look into these

Cass27

Evertjan. wrote:
cass27 wrote on 31 aug 2006 in comp.lang.javascript:
I shall consider myself told off. I think my course is a bit ancient.
And its only fundementals. For instance I had never heard of innerHTML.
What is this actually doing?

[please do not toppost on usenet]

Read the many online tutorials:

http://google.com/search?q=tutorial+javascript

and even before that this newsgoup's FAQs:

<http://www.jibbering.com/faq/>

and

<http://www.merlyn.demon.co.uk/js-index.htm>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 31 '06 #8

P: n/a
Thanx Rob. I think you covered everything.

Cass27

RobG wrote:
cass27 wrote:
I am just doing a course on Javascript and have begun to try out
different ideas. The effect I wanted was fro the user to click on a
graphic. Aprompt box would apprear asking their name and that imfo
would be transferred to the top of that page. However the users name
will only appear on a seperate page.

Tip 1: after the page has finished loading, document.wirte first calls
document.open, which clears the current page before writing the new
content.

The code i am using (in brief) is as follows:

function getname()
{
myname = prompt("What is your name?","");
document.write("<font size 3>Welcome</font>");

Tip 2: use a modern version of HTML. The font element was deprecated
in 1997 with HTML 4.0.
[...]
does anyone know how I cn get the users name to appear on the same page
(without using text box)? Maybe it cant be done using javascript.

Tip 3: learn about getElementById and how to change the value of a text
node.

Start with the FAQ:
<URL: http://www.jibbering.com/faq/#FAQ4_15 >

Continue at quirksmode:
<URL: http://www.quirksmode.org/ >
--
Rob
Aug 31 '06 #9

P: n/a
cass27 wrote on 31 aug 2006 in comp.lang.javascript:
Thanx for your help. I will definately look into these

Cass27

Evertjan. wrote:
>cass27 wrote on 31 aug 2006 in comp.lang.javascript:
I shall consider myself told off. I think my course is a bit
ancient. And its only fundementals. For instance I had never heard
of innerHTML. What is this actually doing?

[please do not toppost on usenet]
Will you look into this too, Cass, please?
>Read the many online tutorials:

http://google.com/search?q=tutorial+javascript

and even before that this newsgoup's FAQs:

<http://www.jibbering.com/faq/>

and

<http://www.merlyn.demon.co.uk/js-index.htm>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 31 '06 #10

P: n/a
Evertjan. said the following on 8/31/2006 6:14 AM:
cass27 wrote on 31 aug 2006 in comp.lang.javascript:
>I shall consider myself told off. I think my course is a bit ancient.
And its only fundementals. For instance I had never heard of innerHTML.
What is this actually doing?

[please do not toppost on usenet]

Read the many online tutorials:

http://google.com/search?q=tutorial+javascript
Of those 24,100,000 hits, I am willing to bet there aren't 100 that are
any good. That alone makes that reference more harmful than useful.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 31 '06 #11

P: n/a
Randy Webb wrote on 31 aug 2006 in comp.lang.javascript:
Evertjan. said the following on 8/31/2006 6:14 AM:
>cass27 wrote on 31 aug 2006 in comp.lang.javascript:
>>I shall consider myself told off. I think my course is a bit ancient.
And its only fundementals. For instance I had never heard of innerHTML.
What is this actually doing?

[please do not toppost on usenet]

Read the many online tutorials:

http://google.com/search?q=tutorial+javascript

Of those 24,100,000 hits, I am willing to bet there aren't 100 that are
any good. That alone makes that reference more harmful than useful.
I do not think so, Randy, being overhitted by Google is all in the game.
Part of the help is giving a learning choice.
Your or my preferred tutorial does not have to be the OP's.

The learning curve is pushed more in the right direction
by letting the OP find out for him/herself that

http://google.com/search?q=tutorial+...ript+innerHTML
528,000 hits, and

http://www.google.com/search?q=javas...rial+innerHTML
710 hits,

could be the next steps.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 31 '06 #12

P: n/a
JRS: In article <Xn********************@194.109.133.242>, dated Thu, 31
Aug 2006 09:24:55 remote, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.netposted :
>
And do not use <fontnomore,
[you must have ancient course material!],
use css styles instead.
CSS may be too big a step for a slow learner (evidently he's not yet
understood about top-posting and ostracism) although it will need to be
learnt. For the moment, I suggest <big& <smallor .big() & .small().

OP : read the newsgroup and its FAQ.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 31 '06 #13

P: n/a
Dr John Stockton wrote on 31 aug 2006 in comp.lang.javascript:
For the moment, I suggest <big& <smallor .big() & .small().
As a shortcut, I would like being able to use:

<.big>... </.big>
for
<div class='big'>...</div>
or
<span class='big'>...</span>

where the default style='display:;' mode is open for discussion.

Is there a way we could, after discussion on usenet,
suggest this for future html/css standard?

Javascript manipulaton could still be done by id as in
<.x id='b1'>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 1 '06 #14

P: n/a

Evertjan. wrote:
Dr John Stockton wrote on 31 aug 2006 in comp.lang.javascript:
For the moment, I suggest <big& <smallor .big() & .small().

As a shortcut, I would like being able to use:

<.big>... </.big>
for
<div class='big'>...</div>
or
<span class='big'>...</span>

where the default style='display:;' mode is open for discussion.
That seems pretty similar to the existing <bigand <smallelements
which can be nested to create bigger/smaller text:

<URL: http://www.w3.org/TR/html4/present/g....html#edef-BIG >
--
Rob

Sep 1 '06 #15

P: n/a
RobG wrote on 01 sep 2006 in comp.lang.javascript:
>
Evertjan. wrote:
>Dr John Stockton wrote on 31 aug 2006 in comp.lang.javascript:
For the moment, I suggest <big& <smallor .big() & .small().

As a shortcut, I would like being able to use:

<.big>... </.big>
for
<div class='big'>...</div>
or
<span class='big'>...</span>

where the default style='display:;' mode is open for discussion.

That seems pretty similar to the existing <bigand <smallelements
which can be nested to create bigger/smaller text:

<URL: http://www.w3.org/TR/html4/present/g....html#edef-BIG >
I am sorry, but they are not, after the point/period comes the css
classname in my proposal:

..sheep {display:block;float:left;border:...;}
..z {display:inline;color:green;font-weight:800;}

<.sheep>floating flock/block</.sheep>

<.z>this is inline text</.z>

The above is much more versatile than manipulating
<bor <ilike:

b {color:red;}

Sorry, this is getting OT.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 1 '06 #16

P: n/a
Evertjan. said the following on 8/31/2006 8:01 AM:
Randy Webb wrote on 31 aug 2006 in comp.lang.javascript:
>Evertjan. said the following on 8/31/2006 6:14 AM:
>>cass27 wrote on 31 aug 2006 in comp.lang.javascript:

I shall consider myself told off. I think my course is a bit ancient.
And its only fundementals. For instance I had never heard of innerHTML.
What is this actually doing?
[please do not toppost on usenet]

Read the many online tutorials:

http://google.com/search?q=tutorial+javascript
Of those 24,100,000 hits, I am willing to bet there aren't 100 that are
any good. That alone makes that reference more harmful than useful.

I do not think so, Randy, being overhitted by Google is all in the game.
I wasn't referring to being overhit, it is the quality of the sites that
I was questioning. Referring a newbie to a lot of bad sites does more
harm than good because they learn all the bad habits and inevitably end
up here saying "But I read on site such and such that eval was a good
thing".
Part of the help is giving a learning choice.
Your or my preferred tutorial does not have to be the OP's.
That is very true. And I don't have a "preferred tutorial" but I do have
a preferred - proven - preferred resource.
The learning curve is pushed more in the right direction
by letting the OP find out for him/herself that

http://google.com/search?q=tutorial+...ript+innerHTML
528,000 hits, and

http://www.google.com/search?q=javas...rial+innerHTML
710 hits,

could be the next steps.
The best step for *anybody* wanting to know something about JS would be:

http://jibbering.com/faq

And then:

http://groups.google.com/group/comp.lang.javascript

Because you can not find two better references - anywhere - for learning
Javascript.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 1 '06 #17

P: n/a
Randy Webb wrote on 01 sep 2006 in comp.lang.javascript:
>could be the next steps.

The best step for *anybody* wanting to know something about JS would be:

http://jibbering.com/faq
Hobble back to my posting where suggested that.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 1 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.