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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript & HTML output error

Status
Not open for further replies.

josephk73

Technical User
Aug 1, 2002
115
GB
Hi guys, I need to create a HTML button inside a VB script, but getting an error. To keep things simple I have included two snippets that I'm using. The first snippet does not work. The second snippet works.

For ease of reading, I've omitted all the metadata stuff at that heads up the beginning of each html script.

Snippet #1

Code:
<title>Untitled Document</title>
</head>
<body>
<input type="button"  value="bye" onclick="test()">


<script language="vbscript">

'when the button is inside a routine (sub or function) it dosent work.

Sub test
document.write "<input type=""button""  value=""hello"" onclick=""hellome()"">"
End sub

Function hellome
Msgbox("hey baby!!!")
End Function

</script>
</body>
</html>
This produces the following error message:
Line:1
Char:1
Error: Object expected
Code:0

Snippet #2

Code:
<title>Untitled Document</title>
</head>
<body>
<script language="vbscript">

'when the button is outside a routine (sub or function) it works.
document.write "<input type=""button""  value=""hello"" onclick=""hellome()"">"


Function hellome
Msgbox("hey baby!!!")
End Function

</script>
</body>
</html>

If anybody has got any ideas why snippet #1 dosen't work I would be grateful.

Thanks in advance guys.
 
snippet #1
[tt]
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<input type="button" value="bye" onclick="test()">

<script language="vbscript">

'when the button is inside a routine (sub or function) it dosent work.

Sub test
document.write "<input type=""button"" value=""hello"" onclick=""hellome()"">"

[blue]'add these as it is document.write and it rewrites the whole page: that's why
document.write "<script language=""vbscript"">" & vbcrlf
document.write "function hellome" & vbcrlf
document.write "Msgbox(""heybaby!"")" & vbcrlf
document.write "end function" & vbcrlf
document.write "<" & "/script" & ">"
[/blue]
End sub

[green]'these are being pointless
Function hellome
Msgbox("hey baby!!!")
End Function
[/green]
</script>
</body>
</html>
[/tt]
In any case, it is just testing for testing sake. Abuse and mis-use of document.write are common mistake of novice.
 
Tsuji - thanks for your help. That works fine. I knew I must have making some kind of illegal statement but didn't know exactly where. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top