variable problem
i would like to do this, but no works:
function putOn()
{
for (i = 0; i <document.f.elements.length; i++)
{
document.f.c"i".checked = true; ( checkbox)
document.f.st"i".value ='5'; (combo box)
}
}
I have multiple checkboxes, and combo boxes with this names:
document.f.c1, document.f.st1
document.f.c2, document.f.st2
"""
and I woul like to reference all documents
I tried to do this:
document.f.c+i+.checked = true;
document.f.st+i+.value ='5';
but no works
Last edited by becknetstat; 01-04-2005 at 06:00 AM .
Objects in JavaScript can also be addressed as associative arrays:
document.f.c['i'].checked = true
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.
Tim Berners-Lee, W3C Director and inventor of the World Wide Web
thanks Charles
I tried to to this, but no works
function putOn()
{
for (i = 0; i <document.f.elements.length; i++)
{
document.f.c['i'].checked = true;
document.f.st['i'].value = '5';
}
}
for example, in Php I can do:
PHP Code:
for ( $i = 1 ; $i < $max ; $i ++)
{
document . f . st ". $i ." . value = '5' ;
document . f . c ". $i ." . checked = 1 ;
}
and create a loop for for do this:
document.f.st1.value='5'
document.f.c1.checked= 1
document.f.st2.value='5'
document.f.c2.checked= 1
document.f.st3.value='5'
document.f.c3.checked= 1
document.f.st4.value='5'
document.f.c4.checked= 1
but I donīt know hom do something similar in javascript
Try:
function putOn()
{
for (i = 0; i <document.f.elements.length; i++)
{
document.f.c[i].checked = true;
document.f.st[i].value = '5';
}
}
<HTML>
<Head>
<Script Language=JavaScript>
function putOn(isForm){
nElements = isForm.length;
for (i=0; i<nElements; i++)
{
if (isForm[i].type == 'checkbox'){isForm[i].checked = true}
if (isForm[i].type == 'text'){isForm[i].value = '5'}
}
}
</Script>
</Head>
<Body>
<Form name='f'>
C1: <input type=checkbox name='c1'>
C2: <input type=checkbox name='c2'>
C3: <input type=checkbox name='c3'>
<br>
ST1: <input type=text name='st1' size=5>
ST2: <input type=text name='st2' size=5>
ST3: <input type=text name='st3' size=5>
<br>
<input type=button value="Put On" onclick="putOn(this.form)">
</Form>
</Body>
</HTML>
thanks for your answers
I tried to do
i = 1;
document.f.c[i].checked = true;
no works
error: object 'document.f.c' is null or not an object
but if I do this:
document.f.c1 .checked = true;
WORKSSS !!!!!, checkbox "c1" its selected, but I canīt do a bucle for select all the checkboxes "c[i]" example.(c1, c2, c3, c4, c5,....)
WHY????
Just use something like this in your loop:
document.f['c'+i].checked=true;
PJ
I tried your solution:
document.f['c'+i].checked=true;
and.....
WORKS
ThanKīs
You're welcome!
PJ
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks