Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document.Write 1

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
Hi
I'm trying to make a small VBScript program on a webpage for my site.
It is just for a laugh, a user inputs their name, friends name etc, and this input value is printed out in amongst a pre-set story.
And I CANNOT make it work, could someone take a look, and tell me what I'm doing wrong, or alternative ways of doing it!!

<html>
<body>
<form name=&quot;game&quot;>
<input length=&quot;20&quot; type=&quot;text&quot; name=&quot;entry1&quot;>
<Input Type=Button Value=&quot;Go!&quot; onClick=&quot;print&quot;>
</form>
<p>
<p>
<p>
<p>
<p>
<br>
<script language = VBScript>
dim entry
entry = Document.game.entry1.Value
</script>
<font face=arial size=5>
hi, the word you typed should apear here!.......----->
<script language = VBScript>
Sub print()
Document.write entry
End Sub
</script>
</font>
</body>
</html>

Any suggestions would be great!!
cheers!
JOE
 
I changed a few things around..
First off, I made print say printIt since print is technically a reserved BASIC word.

I made printIt a function.

printIt now recieves one parameter. You could just as easily use no params and say
Code:
.innerHTML ... & document.game.entry1.value
instead of using text, but I think the parameter is easier to work with and read.

using simply document.write will erase the contents of your current document, so I created a SPAN to hold the HTML that you are going to modify, and used that to add the text.

<html>
<body>
<script language=VBS>
Function printIt(text)
ModifyText.innerHTML = ModifyText.innerHTML & text
End Function
</script>

<form name=&quot;game&quot;>
<input length=&quot;20&quot; type=&quot;text&quot; name=&quot;entry1&quot;>
<Input Type=Button Value=&quot;Go!&quot; onClick=&quot;printIt(document.game.entry1.value)&quot;>
</form>
<p>
<p>
<p>
<p>
<p>
<br>

<script language = VBScript>
dim entry
entry = Document.game.entry1.Value
</script>
<font face=arial size=5>

<SPAN ID=&quot;ModifyText&quot;>hi, the word you typed should apear here!.......-----></SPAN>

</font>
</body>
</html>
 
wow, that is grat.
tahnkyou so much, I'm learning from it too.
there's just one more question, I'll try and figure it out, but if anyone knows I'd be deeply grateful.
How would I do this for multiple Inputs.
So you could have your name, and say..age appear?
because at the moment the button can only be called on to caryy out one function, what or how could I create a function that would write all the values of all the Input boxes.
If anyone could help that'd be great.
thanx for everything.
JOE
 
<script language=&quot;VBScript&quot;>
function updatePage()
username.innerHTML = document.game.UserName.value
age.innerHTML = document.game.Age.value
end function
</script>

<FORM name=&quot;game&quot;>
name <input type=&quot;text&quot; name=&quot;UserName&quot;><BR>
age <input type=&quot;text&quot; name=&quot;Age&quot;><BR>
<Input type=&quot;BUTTON&quot; Value=&quot;Go!&quot; onClick=&quot;updatePage()&quot;>
</form>



<body>
Hello my name is <span ID=&quot;username&quot;></span> and my age is <span ID=&quot;age&quot;></span>
</body>
 
hello again.
I really do appreciate all the help I've got with this problem. I have used it, and have come up with a page using the method suggested, however I keep getting a &quot;do you wish to debug? no such a object 'name' found&quot; or something like that.
Please help...once again!! and I will be forever indetted to you!

<html>
<script language=&quot;VBScript&quot;>
function updatePage()
name.innerHTML = document.game.name.value
best.innerHTML = document.game.best.value
inches.innerHTML = document.game.inches.value
crush.innerHTML = document.game.crush.value
celebrity.innerHTML = document.game.celebrity.value
instrument.innerHTML = document.game.instrument.value
body.innerHTML = document.game.body.value
verb.innerHTML = document.game.verb.value
fav_band.innerHTML = document.game.fav_band.value
dis_band.innerHTML = document.game.dis_band.value
fav_sup.innerHTML = document.game.fav_sup.value
fav_song.innerHTML = document.game.fav_song.value
end function
</script>

<FORM name=&quot;game&quot;>
name <input type=&quot;text&quot; name=&quot;name&quot;><BR>

best friend's name <input type=&quot;text&quot; name=&quot;best&quot;><BR>

a random No. <input type=&quot;text&quot; name=&quot;inches&quot;><BR>

your crush's/girlfriend's/boyfriend's name <input type=&quot;text&quot; name=&quot;crush&quot;><BR>

a celebrity's name<input type=&quot;text&quot; name=&quot;celebrity&quot;><BR>

choose an instrument <select name=&quot;instrument&quot;><br>
<option>guitar
<option>drum
<option>bongo
<option>maracca
<option>bass
<option>banjo
<option>piano
<option>whistle
<option>dijeridoo
<option>recorder
<option>flute
<option>microphone
<option>deck
<option>spoon
<option>voilin
</select>
<br>
a body part <input type=&quot;text&quot; name=&quot;body&quot;><BR>

a verb ('ed..e.g kickED) <input type=&quot;text&quot; name=&quot;verb&quot;><BR>

your favourite band <input type=&quot;text&quot; name=&quot;fav_band&quot;><BR>

your most despised band <input type=&quot;text&quot; name=&quot;dis_band&quot;><BR>

your favourite member of Suppers Ready choose an instrument <select name=&quot;fav_sup&quot;><br>
<option>Tom Holmes
<option>Tom Briton
<option>Tom Jordon
<option>Ben Harvey
<option>Ali Brais
</select>
<br>
your favourite song EVER! <input type=&quot;text&quot; name=&quot;fav_song&quot;><BR>

<Input type=&quot;BUTTON&quot; Value=&quot;Go!&quot; onClick=&quot;updatePage()&quot;>
</form>


<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<body>
One day
<span ID=&quot;name&quot;></span> was invited to go to a gig by their mate
<b><span ID=&quot;best&quot;></span></b>.
It was to go and see this AMAZING new band called Suppers Ready, who were being supported by
<b><span ID=&quot;fav_band&quot;></span></b>.
Of course
<b><span ID=&quot;name&quot;></span></b> said they'd be delighted to go!...so they did.
<br>
On the journey there, they found a
<b><span ID=&quot;instrument&quot;></span></b> ,just casually left on the bus. So
<b><span ID=&quot;name&quot;></span></b> and
<b><span ID=&quot;best&quot;></span></b>
picked it up.
<br>
Anyway, they reached the gig venue, and were overwhelmed by the sheer number of fans there for Suppers Ready (and of course one or two die hard fans of
<b><span ID=&quot;fav_band&quot;></span></b> wandering around, trying not to give in to the overwhelming desire to follow Suppers Ready).............(they gave in eventually)
<br>
Well, after Suppers Ready had done most of their set,
<b><span ID=&quot;name&quot;></span></b> was just thinking it couldn't get any better........when
<b><span ID=&quot;fav_sup&quot;></span></b> announced they were just about to play
<b><span ID=&quot;fav_song&quot;></span></b>.
<br>
Well
<b><span ID=&quot;name&quot;></span></b> and his mate
<b><span ID=&quot;best&quot;></span></b> were so chuffed they both jumped, moshed and accidentaly
<b><span ID=&quot;verb&quot;></span></b>
<b><span ID=&quot;celebrity&quot;></span></b> who had heard of Suppers ready through and had decided to come along and see for themselves what they were like.
<br>
As the evening grew to a close
<b><span ID=&quot;name&quot;></span></b> and
<b><span ID=&quot;best&quot;></span></b> felt they had had a jolly good night, and decided to finish it off they'd like to get Suppers ready's autographs.
So they went back-stage....only to find
<b><span ID=&quot;fav_sup&quot;></span></b> with
<b><span ID=&quot;celebrity&quot;></span></b>, who was helping
<b><span ID=&quot;fav_sup&quot;></span></b> hold the
<b><span ID=&quot;instrument&quot;></span></b>
<b><span ID=&quot;inches&quot;></span></b> inches up their
<b><span ID=&quot;body&quot;></span></b>!!!
<br>
Well, after
<b><span ID=&quot;name&quot;></span></b> and
<b><span ID=&quot;best&quot;></span></b> had, had a good laugh about this (having still gotton the autographs they wanted), they decided to walk home. As it was a charming evening
<b><span ID=&quot;name&quot;></span></b> met up with
<b><span ID=&quot;crush&quot;></span></b> and they all helped to crowdsurf
<b><span ID=&quot;dis_band&quot;></span></b> over the road into oncoming traffic.


</body>
</html>

sorry it's quite long, and u can see it's in aid of a rather immature persuit, but I'd love it if someone coud help!
thanx JOE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top