Prosze o pomoc w nastepujacej sprawie bo osiwieje.
Chcialem skorzystac z funckcji getElementsByName podczas iteracji przez
wszystkie pola formularza zeby ukryc odpowiednie elementy.
Wszystko dziala ok w firefoxie natomiast w IE nie.
Chodzi o kod w tej klauzuli:
if(groupElementsCount>parseInt(groupMinRepeats) && groupMinRepeats ){
..
}
W firefoxie id elementu grupy elegancko jest wyswietlane natomiast w IE cisza.
Czym jest obiekt zwracany przez getElementsByName w IE?
Dlaczego nie jest tablica obiektow html tak jak w firefoksie?
groupFound.length w FF zwraca 2 (co jest poprawne bo sa dwa takie elementy) w IE 0.
Szukalem wczoraj rozwiazania na wlasna reke ale jakos mi nie wyszlo, chyba juz mialem tego dosc. Prosze o pomoc lub wskazowki.
Kod
if(groupName){
groupMaxRepeats = formElement.getAttribute('group_max_repeats');
groupMinRepeats = formElement.getAttribute('group_min_repeats');
groupActRepeat = formElement.getAttribute('group_act_repeat');
groupElementContainer =document.getElementById('TR_Field_'+fieldName);
if(groupMinRepeats){
groupContainer[a++] = fieldParent;
}
groupElementsCount = array_search(groupContainer,fieldParent);
if(groupElementsCount>parseInt(groupMinRepeats) && groupMinRepeats ){
//
// O TEN FRAGMENT KODU CHODZI
//
groupFound = document.getElementsByName(groupName);
for( hide=0; hide < groupFound.length; hide++){
// W FF WYSWIETLA TR_Field_ID_... OK
// W IE WYSWIETLA NIC!!
alert(groupFound[hide].getAttribute('id'));
//groupFound[hide].style.display = 'none';
}
}
else{
formElement.value = parseInt(groupElementsCount);
}
}
groupMaxRepeats = formElement.getAttribute('group_max_repeats');
groupMinRepeats = formElement.getAttribute('group_min_repeats');
groupActRepeat = formElement.getAttribute('group_act_repeat');
groupElementContainer =document.getElementById('TR_Field_'+fieldName);
if(groupMinRepeats){
groupContainer[a++] = fieldParent;
}
groupElementsCount = array_search(groupContainer,fieldParent);
if(groupElementsCount>parseInt(groupMinRepeats) && groupMinRepeats ){
//
// O TEN FRAGMENT KODU CHODZI
//
groupFound = document.getElementsByName(groupName);
for( hide=0; hide < groupFound.length; hide++){
// W FF WYSWIETLA TR_Field_ID_... OK
// W IE WYSWIETLA NIC!!
alert(groupFound[hide].getAttribute('id'));
//groupFound[hide].style.display = 'none';
}
}
else{
formElement.value = parseInt(groupElementsCount);
}
}
SOS
--------------------------
sobie poradzilem
internet explorer w dosc specyficzny sposób rozumie znaczenie tej funkcji:
getElementsById zwraca kolekcje obiektów z takim samym name i id.
Jeżli element ma tylko name o okreslonej wartosci nie zostanie przez ta funkcje odnaleziony.
Diablo sprytnie wymyślone. Mniej wiecej 3.5 godziny bezzsensownej straty czasu.