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

HTA popup, form and checkboxes 4

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi All,

I have an HTA (writen in VBScript (yes I know - bare with me)) that spawns a popup using showModalDialog. The onload function of the child window dynamically builds a list of all Active Directroy Security groups in our domain.

The dynamic table has check boxes. There is a button (calling a js function) that should select all the security groups in the table. I pinched the code from a different project that used IFRAME's rather than dialogs (that worked).

The error I get is: "Line 3: Object required: 'this'"

I just can't see why it is giving this error.

Here is (most) of the code from the child page sgPage.hta:

Code:
<form id="sgForm" name="sgForm">
	<input type="button" id="idBtn" value="OK" onclick="CloseWindow()">
	<input id="BtnChkAll" type="button" value="Check All" onclick="CheckAll this.Form,'chkctrl',true" style="witdth:115px">
	<DIV ID="oTableContainer"></DIV>
	<input type="button" id="idBtn" value="OK" onclick="CloseWindow(sgForm.form)">
	<table id="sgTable"></table>
</form>


<script language="javascript" >
	
	function CheckAll(theForm,CheckName,State){
		elemArray=theForm.elements[CheckName];
		for (i=0;i<elemArray.length;i++){
			elemArray[i].checked=state;
		}
	}
</script>

If it's any help, the line of code in VBScript that creates the checkbox in the table is:
Code:
oTBody0.appendChild(oRow)
    		'Column 1 - Select
    		Set oCell = document.createElement("<TD CLASS='cSelect'>")
    		oCell.innerhtml = "<input type=""checkbox"" id=""chkCtrl"" name=""chkCtrl"" value"""+group+""">"
    		oRow.appendChild(oCell)

It's not referencing the parent window, so assuming there would be a problem if it were, there shouldn't be here.

I am stumpted as to why it cannot see the form.

Any help, pointer would be greatly apreciated.

Many thanks,

Woter,

P.S. I am no JavaScript expert.
 
Hi

In JavaScript the parenthesis ( () ) are mandatory in function calls :
Code:
<input id="BtnChkAll" type="button" value="Check All" onclick="CheckAll[COLOR=red pink]([/color]this.Form,'chkctrl',true[COLOR=red pink])[/color]" style="wi[red][s][gray]t[/gray][/s][/red]dth:115px">

Feherke.
 
Thank you Feherke.

I had tried that as the original used parenthesis, but I was getting an error when loading the page: "Cannot use paranethesis when calling a sub". However, I have now put in javascript: and a semi-colon (;) at the end. So the line now reads:

Code:
<input id="BtnChkAll" type="button" value="Check All" onclick="javascript:CheckAll(this.Form,'chkctrl',true);" style="witdth:115px">

The error from my original post has now gone away, however I am presented with a new error:

in line:
elemArray=theForm.elements[CheckName];

"'Elements' is null or not an object"

I assume this means it cannot find anything to put in the array. From my logic, it should be putting CheckName (chkCtrl) into the array. If I am correct, any ideas why? Something to do with not being able to find theForm (sgForm) perhaps?

Many thanks

Woter.
 
Hi

That is strange. The [tt]javascript:[/tt] pseudo-protocol is certainly wrong there. Is there any [tt]Content-Script-Type[/tt] specified, either in [tt]meta[/tt] tag or HTTP header ? If yes, correct it, if not add it :
Code:
<meta http-equiv="Content-Script-Type" content="text/javascript">

Feherke.
 
Hi Fekerke,

There was no meta tag. I have now added it in the <HEAD> tag. No change though :-(. I wonder if the code below is affecting it. The original IFRAME version had VBScript and JS code in the same way.


Code:
<SCRIPT src="bin\main.vbs" language="VBScript"></script>
<SCRIPT src="bin\start.vbs" language="VBScript"></script>

Many thanks
 
Hi Tsuji,

I take it you mean the function cannot find [tt]this.form[/tt]. Which is what I have been thinking. But why?

I would assume (do a lot of that) that if the code [tt]this.form[/tt] was inside a [tt]<form></form>[/tt] tag, it would know I was refering to controls / objects in that form? If I were refering to another form, then I would call it by name eg. [tt]myOtherForm.form[/tt].

Many thanks
 
Hi

tsuji means to correct the function call ( again ). JavaScript is case sensitive.
Code:
<input id="BtnChkAll" type="button" value="Check All" onclick="CheckAll(this.[COLOR=red pink]f[/color]orm,'chkctrl',true)" style="width:115px">

Feherke.
 
Thanks guys.

Note to self:

JAVASCRIPT is CaSeSeNsAtIvE!!!

It works now. Funny that!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top