![]() |
Object doesn't support this property or method error
HI all. I'm trying to create a tabbed HTA that allows me to pull a
list of user groups on one tab, compare groups on another tab, and assign groups on the 3rd tab. The first and second tabs will display the list of groups in an innerHTML, but the button to run the function isn't working. Here's the code I'm using: <html> <head> <title>AD User Group Migration Tool</title> <link href="testweb.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> hideLayer('lyr3') var origWidth, origHeight; if (document.layers) { origWidth = window.innerWidth; origHeight = window.innerHeight; window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); } } var cur_lyr; function swapLayers(id) { if (cur_lyr) hideLayer(cur_lyr); showLayer(id); cur_lyr = id; } function showLayer(id) { var lyr = getElemRefs(id); if (lyr && lyr.css) lyr.css.display = "block"; } function hideLayer(id) { var lyr = getElemRefs(id); if (lyr && lyr.css) lyr.css.display = "none"; } function getElemRefs(id) { var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null; if (el) el.css = (el.style)? el.style: el; return el; } var arrUsers = new Array(1); WshNetwork = new ActiveXObject("Wscript.Network"); strUserDomain = WshNetwork.UserDomain function ExitProgram(){ window.close(); } function TabStrip_Change(){ switch(TabStrip.Value){ case 0: Page1.style.visibility = "hidden"; Page0.style.visibility = "visible"; Page2.style.visibility = "hidden"; case 1: Page0.style.visibility = "hidden"; Page1.style.visibility = "visible"; Page2.style.visibility = "hidden"; case 2: Page0.style.visibility = "hidden"; Page1.style.visibility = "hidden"; Page2.style.visibility = "visible"; } } function btnGet_Click(){ var sUser1 = User1.value ; var sUser2 = User2.value; for (oGroup in objUser.Groups) { var sGroups = sGroups + oGroup.Name + '\r\n' + "<br>" ; } Next ; document.getElementById('DataArea').innerHTML = sGroups; } // Constants for the NameTranslate object. function btnComp_Click(){ WshNetwork = new ActiveXObject("Wscript.Network"); arrUsers(0) = User1.value; arrUsers(1) = User2.value; for (i = 0; i<=1;) if(i = 0){ UserGroup1.InnerHTML = GetAllGroups(i); }else if(i = 1){ UserGroup2.InnerHTML = GetAllGroups(i); } Next; } function btnRun_Click(){ //text box values sUser1 = User1.value; sUser2 = User2.value; objUser = GetObject("WinNT://" + strUserDomain + "/" + sUser1) objTemplate = GetObject("WinNT://" + strUserDomain + "/" + sUser2) //Pull the Groups for the Template user. for (oGroup in objTemplate.Groups); //Check to see if(the user is already a member; if((ogroup.ismember(objUser.adspath)=False)){; //Add the new user to this group; ogroup.Add(objUser.AdsPath); sGroups = sGroups + oGroup.Name + '\r\n' + "<br>"; } Next; DataArea.InnerHTML = sGroups; } //Put application in wait &&){ clear /** * Delay for a number of milliseconds */ function sleepwait(delay){ var start = new Date().getTime(); while (new Date().getTime() < start + delay); Initialize(4) } //Clear variables function Initialize(){ user1.value = ""; user2.value = ""; Message.InnerHTML = ""; document.getElementById('DataArea').innerHTML = ""; document.getElementById('UserGroup1').innerHTML = ""; document.getElementById('UserGroup2').innerHTML = ""; } function GetAllGroups(i){ // On Error Resume Next WshNetwork = new ActiveXObject("Wscript.Network") ; strDN = WshNetwork.UserDomain; sUser = arrusers(i); objUser = GetObject("WinNT://" + strDN + "/" + sUser); for (oGroup in objUser.Groups); sGroups = sGroups + oGroup.Name + '\r\n' + "<br>"; Next; GetAllGroups = sGroups; } function Testing(){ document.getElementById('DataArea').innerHTML = ""; } </SCRIPT> </head> <body onload="swapLayers('lyr1')"> <div id="section-4"> <ul id="menu"> <li><a href="javascript:void(0)" class="nav-1" onclick="swapLayers('lyr1'); return false">Get Groups</a></li> <li><a href="javascript:void(0)" class="nav-2" onclick="swapLayers('lyr2'); return false">Compare Groups</a></li> <li><a href="javascript:void(0)" class="nav-3" onclick="swapLayers('lyr3'); return false">Assign Groups</a></li> </ul> <table id="contents"><tr><td align="left" valign="top"> <div id="lyr1"> <form id="horizontalForm" action=""> <input id="sUser1" name="sUser1" type="text"/> <input type="button" id="btnGet_Click" value="Get Groups" class="btn" onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'" onclick="btnGet_Click()" /> <p id="DataArea">This is the Data Area.</p> </div> <div id="lyr2"> <div class="alignCenter"><label class="alignTopLeft" for="User1"> <strong>First User ID</strong></label></div> <div class="alignCenter"><input name="User1" id="User1" size="30" maxlength="30" /></div> <input type="button" value="Get Groups" name="btnGet" onClick="btnGet_Click" STyle='background-color: ButtonFace;' STyle='color:ButtonText;'> <br> <div class="alignCenter"><label class="alignTopLeft" for="User2"> <strong>Second User ID</strong></label></div> <div class="alignCenter"><input name="User2" id="User1" size="30" maxlength="30" /></div> </div> <div id="lyr3"> <div class="alignCenter"><label class="alignTopLeft" for="User1"> <strong>New User ID</strong></label></div> <div class="alignCenter"><input name="User1" id="User1" size="30" maxlength="30" /></div> <br> <div class="alignCenter"><label class="alignTopLeft" for="User2"> <strong>Template User ID</strong></label></div> <div class="alignCenter"><input name="User2" id="User1" size="30" maxlength="30" /></div> </div> </td></tr></table> </div> </body> </html> The javascript portion is an attempt at a translation from vbscript, and doesn't give me any errors when I compile, but I get an "Object doesn't support this property or method" error when I click the Get Groups Button. If I change the onClick to the Testing() function, it works, so the problem has to be something in my btnGet_Click function. Could someone look at this and help me determine where I'm going wrong? Thanks! |
Re: Object doesn't support this property or method error
MattW wrote:
> HI all. I'm trying to create a tabbed HTA that allows me to pull a > list of user groups on one tab, compare groups on another tab, and > assign groups on the 3rd tab. The first and second tabs will display > the list of groups in an innerHTML, but the button to run the function > isn't working. Here's the code I'm using: > if (document.layers) { If you write a HTA then why do you need such checks for document.layers which is part of the Netscape 4 object model nobody cares about anymore? Not the cause of your problem but rather odd. > function btnGet_Click(){ > > var sUser1 = User1.value ; > var sUser2 = User2.value; > > for (oGroup in objUser.Groups) > { > var sGroups = sGroups + oGroup.Name + '\r\n' + "<br>" ; > } > Next ; There is no Next statement in JavaScript so drop that line. > UserGroup1.InnerHTML = GetAllGroups(i); By the way, the property is named innerHTML not InnerHTML and JavaScript is case-sensitive. There might be other issues I have not found. -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ |
Re: Object doesn't support this property or method error
On Jun 24, 3:50 pm, MattW wrote:
<snip> > function btnGet_Click(){ <snip> > <input type="button" id="btnGet_Click" value="Get Groups" > class="btn" onmouseover="this.className='btn btnhov'" > onmouseout="this.className='btn'" onclick="btnGet_Click()" /> <snip> Why the XHTML style mark-up when an HTA is only useful on IE and IE does not understand XHTML (will interpret the document at tag-soup HMTL and expend effort error correcting it)? > ..., so the problem has to be something in my btnGet_Click > function. No, it isn't. > Could someone look at this and help me determine where I'm > going wrong? Thanks! Your problem is the scope chain augmentation of functions generated from intrinsic event attributes. When the browser builds a function from the value of your - onclick - attribute it automatically adds a number of objects to the scope chain of that function. Those objects include the INPUT element to which the attribute belongs, the FORM element that contains the attribute and the document object that contains the form. Unqualified Identifiers like - btnGet_Click - are resolved against the scope chain by examining each object on the scope chain in turn to see if it has a named property where then name has the same character sequence as the Identifier ( 'btnGet_Click' in this case). A common 'shortcut' for forms in HTML DOMs is to assign properties to the FORM element whose names correspond with the NAME and/or ID attributes of the form controls contained by the form. This allows access to controls such as - document.forms[0].btnGet_Click - to refer to the INPUT element. So the FORM element is on the function's scope chain, and the form has a property named 'btnGet_Click' which refers to the INPUT element. When the Identifier - btnGet_Click - in - btnGet_Click() - is resolved it resolves as the property of the FORM element named 'btnGet_Click', which refers to the INPUT element, and the attempt to call the INPUT element produces an "object does not support this property or method" error because the INPUT element does not have the internal [[Call]] method and so cannot be called. Richard. |
Re: Object doesn't support this property or method error
On Jun 24, 10:32*am, Martin Honnen <mahotr...@yahoo.de> wrote:
> MattW wrote: > > HI all. *I'm trying to create a tabbed HTA that allows me to pull a > > list of user groups on one tab, compare groups on another tab, and > > assign groups on the 3rd tab. *The first and second tabs will display > > the list of groups in an innerHTML, but the button to run the function > > isn't working. *Here's the code I'm using: > > if (document.layers) { > > If you write a HTA then why do you need such checks for document.layers > which is part of the Netscape 4 object model nobody cares about anymore? > Not the cause of your problem but rather odd. > > > function btnGet_Click(){ > > > var sUser1 = User1.value ; > > var sUser2 = User2.value; > > > * for (oGroup in objUser.Groups) > > * { > > * * * * var sGroups = sGroups + oGroup.Name + '\r\n' + "<br>"; > > } > > Next ; > > There is no Next statement in JavaScript so drop that line. > > > * * *UserGroup1.InnerHTML = GetAllGroups(i); > > By the way, the property is named innerHTML not InnerHTML and JavaScript > is case-sensitive. > > There might be other issues I have not found. > > -- > > * * * * Martin Honnen > * * * *http://msmvps.com/blogs/martin_honnen/ Thanks for your comments, Martin. I'm using the layer check to achieve a tabbed effect. If an alternate method would work better, I'd love to see it, as I'm pretty raw at this, and that was taken from a code sample. The innerHTML tag is actually in the correct case in the btnGet_Click function, but I've corrected the case in the other areas of the script and dropped the Next, still the same error. Thanks for trying to help, though. |
Re: Object doesn't support this property or method error
On Jun 24, 10:35*am, Richard Cornford <Rich...@litotes.demon.co.uk>
wrote: > On Jun 24, 3:50 pm, MattW wrote: > <snip>> function btnGet_Click(){ > <snip> > > <input type="button" id="btnGet_Click" value="Get Groups" > > class="btn" onmouseover="this.className='btn btnhov'" > > onmouseout="this.className='btn'" onclick="btnGet_Click()" /> > > <snip> > > Why the XHTML style mark-up when an HTA is only useful on IE and IE > does not understand XHTML (will interpret the document at tag-soup > HMTL and expend effort error correcting it)? > > > ..., so the problem has to be something in my btnGet_Click > > function. > > No, it isn't. > > > Could someone look at this and help me determine where I'm > > going wrong? *Thanks! > > Your problem is the scope chain augmentation of functions generated > from intrinsic event attributes. When the browser builds a function > from the value of your - onclick - attribute it automatically adds a > number of objects to the scope chain of that function. Those objects > include the INPUT element to which the attribute belongs, the FORM > element that contains the attribute and the document object that > contains the form. Unqualified Identifiers like - btnGet_Click - are > resolved against the scope chain by examining each object on the scope > chain in turn to see if it has a named property where then name has > the same character sequence as the Identifier ( 'btnGet_Click' in this > case). > > A common 'shortcut' for forms in HTML DOMs is to assign properties to > the FORM element whose names correspond with the NAME and/or ID > attributes of the form controls contained by the form. This allows > access to controls such as - document.forms[0].btnGet_Click - to refer > to the INPUT element. > > So the FORM element is on the function's scope chain, and the form has > a property named 'btnGet_Click' which refers to the INPUT element. > When the Identifier - btnGet_Click - in - btnGet_Click() - is resolved > it resolves as the property of the FORM element named 'btnGet_Click', > which refers to the INPUT element, and the attempt to call the INPUT > element produces an "object does not support this property or method" > error because the INPUT element does not have the internal [[Call]] > method and so cannot be called. > > Richard. Thanks for your comments, Richard. As the XHTML markup goes, I'm pretty new to HTA's and Javascript, so alot of what I'm using is cobbled together from other examples. Because I'm not a coder by profession, I'm left to learn from my mistakes, and I always appreciate clear direction that helps me move forward. |
| All times are GMT. The time now is 08:44 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.