piattnd
asked on
How to call a VBScript function from button "on click"
I've got the following code trying to call a function and pass variables to the function, but I get the message that I cannot use parantheses while calling a sub....
I'm not calling a sub though....
I'm not calling a sub though....
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css"
href="\\server\path\CSS.css"/>
<TITLE>Profile Cleanup Utility</TITLE>
<HTA:APPLICATION
APPLICATIONNAME="Program"
SCROLL="no"
BORDER="THIN"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
MINIMIZEBUTTON="no"
MAXIMIZEBUTTON="no"
ICON="\\server\path\icon.ico"
>
<script language="VBScript">
'=====================
'Defining variables
'=====================
Const ForReading = 1
const ForWriting = 2
Const ForAppending = 8
Const ADS_SCOPE_SUBTREE = 2
strDate = Date()
intDel = 60
strTotalSize = 0
strMonth = Month(Now)
strDay = Day(Now)
strYear = Year(Now)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
'================================
'Determine location to run script
'================================
Sub RunLocation
strLocation = SelectLocation.Value
select case strLocation
case ""
GroupSelect.innerHTML = ""
case "Boise"
GroupSelect.innerHTML = "<select size='1' width='50' name='SelectGroup' onchange='BoiseSetGroupInfo'>" &_
"<option selected value=''>Make a Selection</option>" &_
"<option value='PPD'>PPD</option>" &_
"<option value='WDTS'>WDTS</option>" &_
"<option value='TRN'>TRN</option></select>"
End Select
End Sub
Sub BoiseSetGroupInfo
strGroup = SelectGroup.Value
select case strGroup
case ""
'nothing
case "PPD"
Offline = "\\server\path\file.txt"
Deleted = "\\server\path\file.txt"
Checked = "\\server\path\file.txt"
strExcelPath = "\\server\path\file.txt"
strMachineGroup = "PPD*"
strGroupLocation = "LDAP://ou=path,ou=path,ou=path,dc=dc,dc=domain,dc=com"
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup(Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation)'>" End Select
End Sub
Function ProcessGroup(Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation)
objCommand.CommandText = "SELECT Name, dNSHostName FROM '" & strGroupLocation & "' WHERE objectCategory='computer' AND dNSHostName='" & strMachineGroup & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields("Name").Value
msgbox(strcomputer)
objRecordSet.MoveNext
Loop
msgbox("Action Complete")
End Function
</script>
</HEAD>
<BODY>
<DIV id="Background_DIV">
<img src= "\\server\path\image.bmp" height=100% width=100%/>
<script type="text/javascript">
{
window.resizeTo(400,300)
window.moveTo(0,0);
}
</script>
<DIV id="LocationSelect_DIV">
<select size="1" width="30" name="SelectLocation" onchange="RunLocation">
<option selected value="">Make a Selection</option>
<option value="Boise">Boise</option>
<option value="Seattle">Seattle</option>
</select>
</DIV>
<DIV id="GroupSelect_DIV" align="Center">
<span id="GroupSelect"></span>
</DIV>
<DIV id="ActionButton_DIV" align="Center">
<span id="StartAction"></span>
</DIV>
<DIV id="Status_DIV">
<span id="CurrentStatus"></span>
</DIV>
</DIV>
</BODY>
</HTML>
Try using:
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='Call ProcessGroup(Offline,Delet ed,Checked ,strExcelP ath,strMac hineGroup, strGroupLo cation)'>"
(Add Call infront of it)
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='Call ProcessGroup(Offline,Delet
(Add Call infront of it)
ASKER
I've tried using call and it doesn't work.
I also rtied what you said, rejoinder, and I don't get a script error, but the echo returns a null value for any of my variables. In other words, the values aren't being passed.
I also rtied what you said, rejoinder, and I don't get a script error, but the echo returns a null value for any of my variables. In other words, the values aren't being passed.
ASKER
Ok so I talked to my scripting buddy and he said I should change the "onclick" portion to something similar to this:
<....onclick= FunctionName '" & variablename & "'>
I was able to get it to work for one of my variables, then tried to do the same thing for all of them, and now I consistently get the error:
"Wrong number of arguments or invalid property assignment"
Keep in mind I have adjusted my Function to reflect that I'm only trying to pass 1 variable for the time being (until I get the dang thing to work with 1 variable).
Thoughts?
<....onclick= FunctionName '" & variablename & "'>
I was able to get it to work for one of my variables, then tried to do the same thing for all of them, and now I consistently get the error:
"Wrong number of arguments or invalid property assignment"
Keep in mind I have adjusted my Function to reflect that I'm only trying to pass 1 variable for the time being (until I get the dang thing to work with 1 variable).
Thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Holy cow, thank you so much! I was literally bashing my head on my desk all morning......
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup Offline,Deleted,Checked,st