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!

Setting true to multiple controls with same name

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I have here a javascript function, it works for some of the stuff.

[tt]
function ShowChild(HID, LID, status)
{
var list = '';
for(var j=0; j<=max; j++)
{
if ((tree[j][3] == HID) & (tree[j][4] == LID))
{
document.all(tree[j][2]).checked = status;
alert(tree[j][2] + &quot; Been checked to &quot; + status);
spnum += 1;
retshow = 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];
}
}
return list;
}
[/tt]

assuming that
document.all(tree[j][2]).checked = status;
(tree[j][2] = name of object)

is the checkbox, it works for any checkbox that doesnt have another checkbox of the same name, because if there are checkboxes with the same names, setting true to it doesnt work, even tho my alert says it has been set for that particular one.

is there a way to check an object if it's an array, and if it is, how to loop thru and make each one the status that I want.
[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]
 
I ended up using this.

for (i=0; i<document.all(tree[j][2]).length; i++)
document.all(tree[j][2],i).checked = status;

however I need to figure out what's the netscape document.? for checkboxes. [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]
 
I've tried .forms and .layers

[tt]
JavaScript Error: document.forms[0] is not a function
JavaScript Error: document.layers is not a function
[/tt]

I just cant get the dang thing to work, netscape is a POS. [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]
 
I think its something like:-

document.formName.elements[n]

where n is the number of each element within the form, starting from 0 and including all inputs.

HTH :) [sig][/sig]
 
well heres the problem, document.forms[0][Name] works, however if one of the object's name is &quot;5&quot; &quot;2&quot; &quot;3&quot; it doesnt goto that name but instead checks the index of 5,2,3. also I cant get NS to see my label properties , I threw in a label=.... inside of the input tags so I could have some extra info to find it with, works great in IE, but NS just refers to it as &quot;Undefined&quot; [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]
 
fatbloke's solution would perfectly work for your objects named &quot;1&quot; or &quot;5&quot; ... don't use the NAME of the objects but their position in the form
and i don't think netscape actually knows the <input>.label property, so i guess you have to leave it :-/ [sig][/sig]
 
um, I HAVE TO USE NAMES, I cannot rely on numerical positions when since numbers will change between browsers, also it's dynamic, it's not static like a pre-written 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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top