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

Make a textbox and fill it with username 1

Status
Not open for further replies.

alfordjj

MIS
Joined
Jul 23, 2003
Messages
80
Location
US
Ok, here's my weird situation.

I'm trying to write a webpage that users fill out and click a submit button to send the info to our help desk. Sounds simple, right? That's what I thought!

Here's what is going on: I want to pull in the current username and computer name of the client and put them into textboxes so that the user can change them if nessisary. I can get the webpage to build the text box with this code -

<script language="vbs">
dim UText, UName, USize, UTabindex
dim netid


netid="bob"
UText="text"
UName="VUsername"
USize="20"
UTabindex="1"
document.Write ("<input type=" & UText & " name=" & UName & " size=" & USize & " _
Value=" & netid & " tabindex=" & UTabindex & ">")

</script>


The problem is that when I add the Set ObjNet = CreateObject("Wscript.Network") line I get an error.

Now, if I change the first line to <script language="text/VBscript"> it will pull the username and computername just fine. However, it won't print.

Help!! I don't know what the difference is. Can someone please tell me how to correct this.

Thanks in advance for your help.
 
can you use response.write? sorry i dont want through you any red ones as idont have my asp books with me
 
No, response.write doesn't seem to work. It gives me an error that says "Error: Object required 'response'"

That is part of my confusion. Most of the stuff I read said I needed to use response.write. Finaly I found where someone talked about document.write.
 
i think the difference it that it is executed on the client rather than ASP but im not in the know

how about Wscript.CreateObject rather than just CreateObject
 
does this help you out???

<script type="text/vbscript">

const forReading = 1
const forWriting = 2
const forAppending = 8

Dim elem, iUpperBound, arrText(), fRead, fso

iUpperBound = 0

set fso = CreateObject("Scripting.FileSystemObject")
set fRead = fso.OpenTextFile("SomeFile.txt", forReading)

While Not fRead.AtEndOfStream

ReDim Preserve arrText(iUpperBound)
arrText(UBound(arrText)) = tFileRead.ReadLine
iUpperBound = iUpperBound + 1

wend

fRead.close

for each elem in arrText

document.write (elem)

next

set fRead = Nothing
set fso = Nothing

</script>
 
this works for me




<script type="text/vbscript">

set WshShell = CreateObject("Wscript.Shell")


document.write (WshShell.ExpandEnvironmentStrings("%username%"))

</script>
 
this might help you



<html>
<head>
<title>Test de formulaire avec IE</title>
</head>
<body bgcolor="#FFFFD2" scroll="no">

<script language="VBScript">
<!--
Dim ready

Sub VALID_OnClick
ready=1
End Sub

Sub ANNUL_OnClick
ready=2
End Sub


' Initialisation
Sub Window_OnLoad()
ready=0
End Sub

Public Function CheckVal()
CheckVal=ready
End function
'-->
</script>

<form name="AppsForm">
<h3><center>Liste d'Applications</center></h3><hr>

<select size="1" name="AppsList">
<option value="Opt1">application1</option>
<option value="Opt2">application2</option>
<option value="Opt3">application3</option>
<option value="opt4">application4</option>
</select>

<hr>
<input type="button" value="Valider" name="VALID">
<input type="button" value="Annuler" name="ANNUL">
</form>
</body>
</html>
 
Good idea, but it didn't work. I just tried it and I get the same error as I do for Response.Write. It wants an object. I'm not sure why.

Here's something interesting, I just tried making two sections and seeing if the variable would pass between them. Here's what I've got

<script language="text/vbscript">
Set ObjNet = CreateObject("Wscript.Network")
set netid=ObjNet.UserName
</script>
<script language="vbs">
dim UText, UName, USize, UTabindex

UText="text"
UName="VUsername"
USize="20"
UTabindex="1"
document.Write ("<input type=" & UText & " name=" & UName & " size=" & USize & " Value=" & _
netid & " tabindex=" & UTabindex & ">")
</script>


This lets the textbox get built, but what shows up as the value is tabindex=1.

Any ideas there?

Thanks!!!!
 
Wow, sorry. Missed those 2 long messages. I'll try those.
 
document.Write ("<input type=" & UText & " name=" & UName & " size=" & USize & " Value=" & _
netid & " tabindex=" & UTabindex & ">")


i think needs to include somethign like

value = " & netid
 
Anyway:
[!]set [/!]netid=ObjNet.UserName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the help everyone!!!

Unfortunatly, none of the ones that are supposed to pull the username are working. I get the following error:

"ActiveX component can't create object:"

The one that tells how to make a form works great, though!!

I'm putting this into Front Page 2002. I get that error when I swap to the "Preview" tab. Is this the right way to do it? I have worked with Front Page before, and the Preview tab always worked before, but I never did scripting before!

Thanks everyone!!
 
Nevermind. I figured it out. Front Page WAS hosing it up. I saved it down to a file and opened it with IE, and it worked perfect.

Here's the code I used:

<script type="text/vbscript">
dim UText, UName, Usize, UTabindex

Set ObjNet = CreateObject("Wscript.Network")

UText="text"
UName="VUsername"
USize="20"
UTabindex="1"

document.write("<dev><input type=" & UText & " name=" & UName & " size=" & USize & " value=" & ObjNet.UserName & " tabindex=" & UTabindex & "></dev>")

Set ObjNet = Nothing
</script>


Many, many thanks, folks!!
 
good stuff, cheers for the input PHV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top