"Evertjan." <ex**************@interxnl.net> a écrit dans le message de
news:Xn********************@194.109.133.29...
Bob Bedford wrote on 01 jul 2004 in comp.lang.javascript:
after Evertjan advice ;), I'm trying to cut down a complex task in
many easier ones.
Here is the code I'm trying to get to work:
function CheckGroup(X){
code = X.value;
alert(code); //this is OK !!!!
obj = document.getElementById('option[]');
alert('object length '+obj.length);
for ( index = 0; index < obj.length; index++ )
{
testcode = obj[index].value;
if(code == testcode)
alert('found...');
}
}
then I print several input type like this:
//generated by PHP...$newvalue are new values at every checkbox
(concat in PHP is ".")
<input type="checkbox" name="option[]" value=".$newvalue."
name="option[]"
1 This is not a HTML legal name.
2 this is not an ID, so getElementById should not find it [exept that som
browsers might have a bug.
3 id ="option[]" would aldso be illegal HTML.
4 you cannot make a javascript array like this
onclick="CheckGroup(this)");>
the ); is illegal
Every checkbox is part of the option array (look at the name). In the
CheckGroup function, I try to retrieve all $newvalue from the option[]
array. So I try to retrieve every single item in the option[] array,
but unfortunately, it doesn't work.
alert(obj.length); show and undefined value.
How can I retrieve such items values ???
I can only exchange PHP [because of my lack of knowledge of PHP]
by ASP(!!!) and you would get something like this:
<% for n= 1 to 25 %>
<input type="checkbox"
name="<%=option(n)%>"
id="<%=option(n)%>"
onclick="CheckGroup(this);"
value="<%=newvalue(n)%>">
<br>
<% next %>
And the clientside javascript can do:
function CheckGroup(X){
id = X.value;
alert(id); //this is OK !!!
}
and
obj = document.getElementById('<%=option(7)%>');
alert(obj.value)
==============
Bob, perhaps we will get somewhere.
Finally, with your help, I got it to work:
javascript
:
function CheckGroup(X){
code = X.value;
alert(code);
obj = document.SubmitForm.option;
for ( index = 0; index < obj.length; index++ ){
alert('object values '+obj[index].value);
}
}
HMTL code:
....
<input type="checkbox" name="option" value="1422862"
onclick="CheckGroup(this)">
<input type="checkbox" name="option" value="1422863"
onclick="CheckGroup(this)">
....
Thanks for your help !!!
Now I will try to store a list of exclusion with this object. If somebody
know how to do so, please let me know.
Regards