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

Using the onclick method 1

Status
Not open for further replies.

teckiejon

Technical User
Feb 25, 2004
47
GB
I have a script that I have written with much assistance from this forum that creates new user accts on the Active Directory. I have decided however that rather than have a series of input boxes to collect information about the new user I would use a web type form. My question is, can anybody advise me on how to pass information from the form to the rest of the script? So that basically whatever was input on the form would be passed as a variable to the rest of the script. The initial form that I have written reads as follows:

set objexplorer = createobject("internetexplorer.application")
objexplorer.navigate2 "about:blank" : objexplorer.width = 650 : objexplorer.height = 350 : objexplorer.toolbar = false : objexplorer.menubar = false : objexplorer.statusbar = false : objexplorer.visible = True

objexplorer.document.write "<font color=blue>"
objexplorer.document.write "<h2>User Account Creation Tool</h2>"

objexplorer.document.write "<table border=" &chr34 & "3" &chr34 & ">"
objexplorer.document.write "<tr>"
objexplorer.document.write " <th>User Name:</th>"
objexplorer.document.write " <td>First name: "
objexplorer.document.write "<input type=" &chr34 & "teoxt" &chr34 & " name=" &chr34 & "firstname" &chr34 & ">"
objexplorer.document.write "Last name:"
objexplorer.document.write "<input type=" &chr34 & "text" &chr34 & " name=" &chr34 & "lastname1" &chr34 & "><br></td>"
objexplorer.document.write "</tr>"
objexplorer.document.write "<tr>"

objexplorer.document.write " <th>Home Server</th>"
objexplorer.document.write " <td><select name=" &chr34 & "City" &chr34 & ">"
objexplorer.document.write "<option value=" &chr34 & "Site1" &chr34 & ">Site1"
objexplorer.document.write "<option value=" &chr34 & "Site2" &chr34 & ">Site2"
objexplorer.document.write "<option value=" &chr34 & "Site3" &chr34 & ">Site3"
objexplorer.document.write "</select></td>"
objexplorer.document.write "</tr>"
objexplorer.document.write "<tr>"

objexplorer.document.write " <th>E Mail Settings</th>"
objexplorer.document.write " <td>Mail Server:"
objexplorer.document.write "<select name=" &chr34 & "Server" &chr34 & ">"
objexplorer.document.write "<option value=" &chr34 & "Exchange-1" &chr34 & ">Exchange-1"
objexplorer.document.write "<option value=" &chr34 & "Exchange-2" &chr34 & ">Exchange-2"
objexplorer.document.write "<option value=" &chr34 & "Exchange-3" &chr34 & ">Exchange-3"
objexplorer.document.write "</select><br>"


objexplorer.document.write "Storage Group:"
objexplorer.document.write "<select name=" &chr34 & "strgroup" &chr34 & ">"
objexplorer.document.write "<option value=" &chr34 & "DB1" &chr34 & ">DB1"
objexplorer.document.write "<option value=" &chr34 & "DB2" &chr34 & ">DB2"
objexplorer.document.write "<option value=" &chr34 & "DB3" &chr34 & ">DB3"
objexplorer.document.write "<option value=" &chr34 & "DB4" &chr34 & ">DB4"
objexplorer.document.write "<option value=" &chr34 & "DB5" &chr34 & ">DB5"


objexplorer.document.write "</select></td>"
objexplorer.document.write "</tr>"
objexplorer.document.write "<tr>"
objexplorer.document.write " <th>Further Access</th>"
objexplorer.document.write " <td>"
objexplorer.document.write "<input type=" &chr34 & "checkbox" &chr34 & " name=" &chr34 & "visio" &chr34 & ">"
objexplorer.document.write "ms_visio2003"
objexplorer.document.write "<br>"
objexplorer.document.write "<input type=" &chr34 & "checkbox" &chr34 & " name=" &chr34 & "access" &chr34 & ">"
objexplorer.document.write "ms_access2002"


objexplorer.document.write "</td>"
objexplorer.document.write "</tr>"
objexplorer.document.write "</table>"
objexplorer.document.write "<br>"
objexplorer.document.write "<input type=" &chr34 & "button" &chr34 & " value=" &chr34 & "Create Account" &chr34 & " onclick=" &chr34 & ">"
objExplorer.document.title = "user Account creation Tool "


Then with a bit of magic in the middle the rest of the script would then follow:

lastname= UCase(lastname1)
initial = LCase(Left(firstName, 1))
initial2 = LCase(Left(firstName, 2))
username1 = LCase(left(lastName,6))
username = username1 & initial
bothName = firstName & " " & lastName
strdisplayname = lastname & " " & firstname & " -my company domain"
strdisplayname1 = lastname & ", " & firstname & " -my company domain"

dim strnames(7)

strnames(0)="OU= Site1 ,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(1)="OU= Site4,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(2)="OU= Site3,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(3)="OU= Site2,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(4)="OU= XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(5)="OU= Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(6)="OU= XP Users,OU=City5,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(7)="OU= Users,OU=City5,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"

for i= 0 to 7

Set objDomain = GetObject("LDAP://" & strnames(i))
For Each objUser In objDomain
If UCase(objUser.sAMAccountName) = UCase(username) Then
'wscript.echo "Username : " & username & " is already being used in the Active Directory."
initial = LCase(Left(firstName, 2))
username1 = LCase(left(lastName,6))
username = username1 & initial
Exit For
End If
Next
next


wscript.echo "Your user has been given the following username: " & username


'This part of the script creates the user account on the server

set objParent = GetObject("LDAP://" & strldap)
set objUser = objParent.Create("user", "cn=" & strdisplayname)

objUser.Put "sAMAccountName", "" & username
objUser.Put "userPrincipalName", "" & username & "@domain.intra.my company.com"
objUser.Put "givenName", "" & firstname
objUser.Put "sn", "" & lastname1
objUser.Put "displayName", "" & strdisplayname1
objuser.Put "physicalDeliveryOfficeName", "" & stroffice
objuser.Put "Description" ,"New user: " & Date
objuser.Put "scriptPath", "pilot.syn"
objUser.TerminalServicesProfilePath = "\\" & strfshare & "\profiles.$\" & username & "\terminal"
objUser.mail = firstname & "." & lastname1 & "@my company.com"

objUser.SetInfo

objUser.SetPassword "password"
objUser.AccountDisabled = TRUE
objuser.setinfo


etc........
I have not been able to search the forum so far as the facility seems to be down so I apologise in advance if this is a simple problem that I should be able to solve myself

 
Hello techiejon,

I cannot be very specific here as I have not scrutinized your script. But if I understand your wording of your need, this brief description might help.

In your page generated on execution of the script, put all the input elements in a form with a name, "formname" say, (or id... so many ways). Then within your page, the clients input can be made always to everywhere of the page by:
[1]textbox
[tt]document.formname.textboxname.value[/tt]
returning text input;
[2]checkbox
[tt]document.formname.checkboxname.checked[/tt]
returning true or false;
[3] radiobutton
[tt]document.formname.radiobuttonname(index).checked[/tt]
returning true or false;
[4] select
[tt]idx=document.formname.selectname.options.selectedindex
document.formname.selectname.options(idx).value
returning the menu entry being selected.
etc...
All these returns can be put to a variable for further processing.

regards - tsuji
 
Tsuji

As per the star many thanks that has got me further as I have now encapsulated the form in <form> </form> brackets and have added the following code:


dim myform
set myform=objexplorer.document.forms("Newuser")
set myform.firstname.value = firstname
set myform.lastname1.value = lastname1
set myform.city.value = strfshare
set myform.server.value = strexsvr

However I have a problem in that I need the script to wait until a button is pressed on the form to continue as all I get at the moment are errors that firstname needs a value. Do you know how I would go about this? Thankyou in anticipation
 
teckiejon,

On the surface of your code, eliminate a couple of set keywords, as it is for an object assignment.

[tt]set myform=objexplorer.document.forms("Newuser")
myform.firstname.value = firstname
myform.lastname1.value = lastname1
myform.city.value = strfshare
myform.server.value = strexsvr[/tt]

The above seem to be an assignment to the initial values for client's approval? To retrieve those into variables, it is the other way around, something like:

[tt]var_firstname=myform.firstname.value
etc...[/tt]

As to waiting, the variables do need a chance to get updated, and this chance happens if there is an event to trigger it. For instance, you have a button type input waiting for the client to press to confirm, when it happens onclick event handler can retrieve those into var_firstname etc (just for example, use your proper variables).

If it never happens, you may provision for a fixed time beyond which those values in the text boxes etc are retieved.

- tsuji
 
...I must be nearly there now!

Tsuji
I have re written and renamed the variable assignments, added a button to the code and tried to echo one of the variables at the end to see if it works. It doesnt! All that happens at the moment is when I submit the form the window goes blank and the script ends. I have enclosed the latest additions to the code, if you have time could you please take a look and let me know where I am going wrong:

objexplorer.document.write "<input type="&chr34 &"image"&chr34 &" name="&chr34 &"submitgif"&chr34 &" src="&chr34 &"c:\submit.gif"&chr34 &" onclick="&chr34 &"submitform()"&chr34 &" border="&chr34 &"0"&chr34 &">"
objexplorer.document.write "</form>"

objexplorer.document.write "<script type="&chr34 &"vbscript"&chr34 &">"
function submitform()

dim myform
set myform=objexplorer.document.forms("Newuser")
var_firstname=myform.firstname.value
var_lastname1=myform.lastname1.value
var_strfshare=myform.strfshare.value
var_strexsvr=myform.strexsvr.value


wscript.echo "" & lastname1

end function
 
teckiejon,

[1] I take submit a form in the sense not according to asp but as all variables finally confirmed by client. Tell me if it is not so.

[2] May need a further debugging, for instance
[tt] chr34 ---> chr(34)?
wscript.echo ""& var_lastname1[/tt]
(But, you know lastname1 by itself is also a variable.) Corect it first see if it keeps the script behave better.

[3] Before you implement this kind of dynamically generated interface, it would be advisible to make the interface in plain htm script, debug it then implement it in the form of dynamic generation (objexplorer.document.write...) This would make the debugging less bumpy. My opinion only...

- tsuji
 
Further note:

I should also note that the function submitform() shown above should be line-by-line document.write to the interface at the right place, not in the plain form as such.

If this is so, have to change wscript.echo to msgbox instead as wscript.echo would not be recognized under the host of objexplorer.

- tsuji
 
Yes the submit function is that all variables have been confirmed on the form

I shall re write the initial code as plain htm and see whether I can get it to work. Thankyou for your continued patience and time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top