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

this keyword not support object... 1

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I have a javascript function, but I Cant use it because it keeps saying cannot use object or something like that, here the function with the line highlighted

[tt]
function createArray(n, init)
{
var i = 0
[red]this.length = n[/red]
for(i = 1; i<n; i++)
{
this = init
}
return this
}
[/tt]

keeps saying Line : 15, object does not support this action, but it worked fine on an htm page I had in the same directory, that same function. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Hi Karl

i rewrite your code little bit and it work for me..
please try this..

function createArray(n, init)
{
this.length = n;
for( var i = 1; i<=n; i++)
this = init;
return this;
}

the problem maybe in the &quot;i<=n&quot;..
hope this helps
[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
I'll give that a try, also the purpose of &quot;init&quot; is to fill each array member with a default value. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
nope still same error, same line as well. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Karl,

i think the problem is how you call the function,
please take a look at my code,

<html>
<script>
function createArray(n, init)
{
this.length = n;
for(var i=1; i<=n; i++)
this = init;
return this;
}

var Temp_data = new createArray(100, &quot;testing&quot;);
alert(Temp_data[50]);
</script>
<body>

</body>
</html>

the code should alert &quot;testing&quot;

[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
Karl,

here the problem..
var Temp_data = new createArray(100, &quot;testing&quot;);
you need to create a new object first.

hope this help

[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
I Got it working ended up using new Array(...) rather than This.length

[tt]
%>
<Script language=&quot;Javascript&quot;>
<!--

function createRow(HID, LID, HName, HP, LP)
{
nary = new Array(5);

nary[0] = HID;
nary[1] = LID;
nary[2] = HName;
nary[3] = HP;
nary[4] = LP;

return nary;
}

tree = new Array(<%=ubound(AryData,2)%>);
<%
for j = lbound(AryData, 2) to ubound(AryData,2)
Response.Write &quot;tree[&quot; & j & &quot;] = createRow(&quot; & AryData(HID,j) & &quot;,&quot; & AryData(LID,j) & &quot;,&quot;&quot;&quot; & AryData(Name,j) & &quot;&quot;&quot;,&quot; & AryData(HP,j) & &quot;,&quot; & AryData(LP,j) & &quot;);&quot; & vbcrlf
next
%>
-->
</Script>
<%
[/tt] [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top