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....
<link rel="stylesheet" type="text/css"
<TITLE>Profile Cleanup Utility</TITLE>
<script language="VBScript">
'Defining variables
Const ForReading = 1
const ForWriting = 2
Const ForAppending = 8
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 ""
					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
		Do Until objRecordSet.EOF
			strComputer = objRecordSet.Fields("Name").Value
		msgbox("Action Complete")
	End Function
<DIV id="Background_DIV">
<img src= "\\server\path\image.bmp" height=100% width=100%/>
<script type="text/javascript">
<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>
<DIV id="GroupSelect_DIV" align="Center">
<span id="GroupSelect"></span>
<DIV id="ActionButton_DIV" align="Center">
<span id="StartAction"></span>
<DIV id="Status_DIV">
<span id="CurrentStatus"></span>

Open in new window

LVL 12
Who is Participating?
rejoinderConnect With a Mentor Commented:
I know why my method returned null... please use this line instead;
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup """ & Offline & """,""" & Deleted & """,""" & Checked & """,""" & strExcelPath & """,""" & strMachineGroup & """,""" & strGroupLocation & """'>"

Drop the () and use double quotes plus ampersand to get your variables into the line.  So easy I forgot that you were passing variables from above :-)

I tested this by using a msgbox in the function and I was able to see all the variables being passed.
The function call should not have parenthesis when you use multiple variables.  Use the following in your code and all should work fine (at least for me it did);
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation'>"
Try using:

                                                StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='Call ProcessGroup(Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation)'>"

(Add Call infront of it)
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

piattndAuthor Commented:
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.
piattndAuthor Commented:
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).

piattndAuthor Commented:
Holy cow, thank you so much!  I was literally bashing my head on my desk all morning......
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.