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

if I have object name in "String" how do I use it to access object

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I have an array , the 3rd item is the name of an object on a page for example like &quot;3_2|Check&quot; how do I access that checkbox by a name I have in a string, so that I Can enable/disable it. [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,

hope this can help you

<html>
<body>
<form>
<input type=checkbox name=&quot;0&quot;>
<input type=checkbox name=&quot;1&quot;>
<input type=checkbox name=&quot;2&quot;>
<input type=checkbox name=&quot;3&quot;>
<input type=checkbox name=&quot;4&quot;>
<input type=checkbox name=&quot;5&quot;>
</form>

<script>
var length = 5
var checkbox = new Array(length);

checkbox[0] = &quot;0|check&quot;;
checkbox[1] = &quot;1|empty&quot;;
checkbox[2] = &quot;2|check&quot;;
checkbox[3] = &quot;3|empty&quot;;
checkbox[4] = &quot;4|empty&quot;;
checkbox[5] = &quot;5|check&quot;;

for (var i=0; i<=checkbox.length-1; i++)
{
if (checkbox.indexOf(&quot;check&quot;,0) >= 0)
document.forms[0].elements.checked = true;
}
</script>

</body>
</html> [sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
um there is a Slight problem with that, my page isnt a Static HTML, it's dynamic, and it gets it's array from the ASP, the ASP does make the Javascript portion hardcode all the values of the array, but the Checkbox etc portion it's not static. [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]
 
heres a small example of the checkboxes/etc generated by the ASP (the Javascript is above it since when I generate the checkboxes etc, they're put into a string, then later output to the browser so that I Could use two columns in the table)

[tt]
<TR><TD bgcolor=&quot;#e6e6fa&quot;>
<input onclick=&quot;javascript:alert(ShowChild(3,1))&quot; type=&quot;Checkbox&quot; name=&quot;3&quot; value=&quot;Industry&quot;>
Industry
</TD></TR>

<TR><TD bgcolor=&quot;#fff4f6&quot;>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input onclick=&quot;javascript:alert(ShowChild(3,2))&quot; type=&quot;Checkbox&quot; name=&quot;3-2|Radio&quot; value=&quot;Employment&quot;>
Employment
</TD></TR>

<TR><TD bgcolor=&quot;#fff4f6&quot;>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input onclick=&quot;javascript:alert(ShowChild(3,3))&quot; type=&quot;Checkbox&quot; name=&quot;3_2|ind_type&quot; value=&quot;Goods&quot;>
Goods Producing
</TD></TR>
[/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]
 
Karl,

can your show me part of your ASP code?
if it is ASP page, it should not be difficult to do that

[sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
Bottom half of the ASP
[tt]
[red]generates the Tabel cells you seen above into a string that is used at the bottom of this ASP
showtreeat AryData, 0,0, &quot;&quot; 'stores Database into HTML formats[/red]

set LangData = nothing
Set ESA = nothing
Set RM = nothing
Set Occ = nothing
set IOC = nothing

' Start of HTML Response
%>
<Script language=&quot;Javascript&quot;>
<!--
var max = <%=ubound(AryData,2)%>
tree = new Array(<%=ubound(AryData,2)+1%>);
var spnum = 0


function spaces(number)
{
var sptmp = '';
for (var sp=0; sp<number; sp++)
sptmp = sptmp + &quot; &quot;;
return sptmp;
}

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;
}
function I plan to make all children checked when parent is checked
function ShowChild(HID, LID)
{
var list = '';
for(var j=0; j<=max; j++)
{
if ((tree[j][3] == HID) & (tree[j][4] == LID))
{
//Need to figure out how to reference an object using it's name in a String
spnum += 1;
retshow = ShowChild(tree[j][0],tree[j][1])
spnum -= 1;
if (retshow != '')
list = list + &quot;\n&quot; + spaces(spnum) + tree[j][2] + retshow;
else
list = list + &quot;\n&quot; + spaces(spnum) + tree[j][2];
}
}
return list;
}

<%
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>
<%
set AryData = nothing
Response.write &quot;<form action=&quot;&quot;FormatMulti.asp&quot;&quot; method=&quot;&quot;Post&quot;&quot;>&quot; & vbcrlf
Response.Write vbtab & &quot;<Table border=0 align=center Width=&quot;&quot;90%&quot;&quot;>&quot; & vbcrlf
Response.Write vbtab & vbtab & &quot;<TR><TD &quot; & gTopColor & &quot; align=center valign=middle colspan=2> <H1> &quot; & LangLookup(&quot;Multi&quot;, &quot;Report&quot;, &quot;Print&quot;) & &quot;</H1> </TD></TR>&quot; & vbcrlf
Response.Write vbtab & vbtab & &quot;<TR>&quot; & vbcrlf
'Output of Table cells showing checkboxes, etc
Response.Write vbtab & vbtab & vbtab & &quot;<TD &quot; & gTableCellColor & &quot; width=&quot;&quot;50%&quot;&quot; valign=top><Table border=0 width=&quot;&quot;100%&quot;&quot;>&quot; & vbcrlf & HTMLStr1 & vbcrlf & &quot;</Table></TD>&quot; & vbcrlf
Response.Write vbtab & vbtab & vbtab & &quot;<TD &quot; & gTableCellColor & &quot; width=&quot;&quot;50%&quot;&quot; valign=top><Table border=0 width=&quot;&quot;100%&quot;&quot;>&quot; & vbcrlf & HTMLStr & vbcrlf & &quot;</Table></TD>&quot; & vbcrlf
'Rest HTML response
Response.Write vbtab & vbtab & &quot;</TR>&quot; & vbcrlf
Response.Write vbtab & vbtab & &quot;<TR><TD &quot; & gBottomColor & &quot; align=center valign=middle colspan=2><input type=&quot;&quot;Submit&quot;&quot;></TD></TR>&quot; & vbcrlf
Response.Write vbtab & &quot;</Table>&quot; & vbcrlf
Response.Write &quot;</form>&quot; & vbcrlf

Response.write &quot;</body>&quot; & vbcrlf & &quot;</html>&quot;

Response.Flush
Response.End
%>
[/tt]

a portion of the showtreeat() function.

[tt]
'<!-- Rescursive Subroutine with starting point -->
sub showtreeat(byref theObj, HpLoc, LpLoc, PName) 'Rescurvily loads tree into HTMLStr1 and HTMLStr
Dim TreeRow
TreeRow = UBound(theObj, 2)
for j = 0 to TreeRow
If theObj(HP,j) = HpLoc and theObj(LP,j) = LpLoc then
'-----------------------------------------------------
'If this is a child of the parent we are searching for
if Change = true then
'Begining of Start second column HTML
If Spaces = 0 then
If count > 45 then
Change = False
HTMLStr1 = HTMLStr
HTMLStr = &quot;&quot;
end if
end if
'End of 2nd HTML
end if
if theObj(RType,j) <> &quot;DataGroup&quot; then
If Spaces = 0 then
HTMLStr = HTMLStr & &quot;<TR><TD &quot; & gHeader2CellColor & &quot;>&quot;
else
HTMLStr = HTMLStr & &quot;<TR><TD &quot; & gTableCellColor & &quot;>&quot;
end if
if Pname = &quot;&quot; then 'will be modified when we need to find parents of children
[red] HTMLStr = HTMLStr & writetabs(Spaces) & vbcrlf & &quot;<input onclick=&quot;&quot;javascript:alert(ShowChild(&quot; & TheObj(HID,j) & &quot;,&quot; & TheObj(LID,j) & &quot;))&quot;&quot; type=&quot;&quot;&quot; & TheObj(RType, j) & &quot;&quot;&quot; name=&quot;&quot;&quot; & TheObj(Name, j) & &quot;&quot;&quot; value=&quot;&quot;&quot; & TheObj(Value,j) & &quot;&quot;&quot;>&quot; [/red]
else
[red] HTMLStr = HTMLStr & writetabs(Spaces) & vbcrlf & &quot;<input onclick=&quot;&quot;javascript:alert(ShowChild(&quot; & TheObj(HID,j) & &quot;,&quot; & TheObj(LID,j) & &quot;))&quot;&quot; type=&quot;&quot;&quot; & TheObj(RType, j) & &quot;&quot;&quot; name=&quot;&quot;&quot; & TheObj(Name, j) & &quot;&quot;&quot; value=&quot;&quot;&quot; & TheObj(Value,j) & &quot;&quot;&quot;>&quot; [/red]
end if
HTMLStr = HTMLStr & TheObj(Label, j)
HTMLStr = HTMLStr & &quot;</TD></TR>&quot; & vbcrlf & vbcrlf
Count = Count + 1
else
....
[/tt]

It would be somewhat difficult, because the list of Checkboxes, and what not in a tree format, comes from an Array generated by .GetRows from a Database, that hold certain header/left etc data to recursivily give the flow a true parent/child relation(a true parent/child is no longer true when it becoems an HTML) [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]
 
currently the showchild function will spit back all the children of a checkbox I click, just to make sure my rescursion is working, and ready when I figure out how to access the checkbox's properties (like checked/unchecked) by just using the name of the checkbox I have stored in a string. [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]
 
also doing this

[tt]
tree[j][2].checked = true;
[/tt]

(I've also tried, on, 1, 0, off, false, and included &quot;&quot; around them as well)

doesnt generate an error, but doesnt do anything either. [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,

let say.. the following HTML are generated by your ASP code
-------------------------------------------
<html>
<body>
<form>
<input type=checkbox name=&quot;0|check&quot;>
<input type=checkbox name=&quot;1|empty&quot;>
<input type=checkbox name=&quot;2|check&quot;>
<input type=checkbox name=&quot;3|empty&quot;>
<input type=checkbox name=&quot;4|empty&quot;>
<input type=checkbox name=&quot;5|check&quot;>
</form>
-------------------------------------

after it, you can place the following javascript code, the only problem is i forgot how to make that &quot;5&quot; in the for loop dynamic, i pretty sure there is a way to detect the length of elements.. or you can let ASP return a count variable tell the javascript how many element are there..


<script>
for (var i=0; i<=5; i++)
if ((document.forms[0].elements.name.indexOf(&quot;check&quot;,0)) >= 0)
document.forms[0].elements.checked = true;
}
</script>

</body>
</html> [sig]<p>Chiu Chan<br><a href=mailto:cchan@gefmus.com>cchan@gefmus.com</a><br><a href= America, Inc</a><br>[/sig]
 
This works great.

function ShowChild(HID, LID, status)
{
var list = '';
for(var j=0; j<=max; j++)
{
if ((tree[j][3] == HID) & (tree[j][4] == LID))
{
//Need to figure out how to reference an object using it's name in a String
//spnum += 1;
ShowChild(tree[j][0],tree[j][1], status)
//spnum -= 1;
//if (retshow != '')
// list = list + &quot;\n&quot; + spaces(spnum) + tree[j][2] + retshow;
//else
// list = list + &quot;\n&quot; + spaces(spnum) + tree[j][2];
document.all(tree[j][2]).checked = status; //test
}
}
//return list;
}

it'll only checks one level below tho [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