Hello, i have two problems with javascript. It�s possible my problem should be placed in other forum but i think only people use
Struts can understand me. Sorry for my english, i will try explain my problem:
I have a Form with one <html:select> and severals fields <html:radio> associated. When i click in one radio field, the list of values change in a select field (others values).
Contenido : <html:select property="contenido" size="1"></html:select>
<html:radio property="tipocontenido" value="conindata" onclic="changeContenidosEjercicio(this.value);"/>Conducta
<html:radio property="tipocontenido" value="gesindata" onclic="changeContenidosEjercicio(this.value);"/>Gesto
I can realize this operation fine with this javascript function (Previosly i have loaded in various arrays (Arrayconindata,Arraygesindata) the diferent values:
------------------------------------------------------
function changeContenidosEjercicio(control){
contenidosArray = new Array();
contenidosEjercicio = document.forms['ejercicioForm'].contenido;
contenidosEjercicio.options.length=0;
if (control == 'conindata') {contenidosArray = Arrayconindata;}
if (control == 'gesindata') {contenidosArray = Arraygesindata;}
for (i=0; i < contenidosArray.length;i++)
contenidosEjercicio.options[i] = contenidosArray[i];
}
-------------------------------------------------------------
Now, i have to recover several beans and show it in a
jsp with their values stored. For realize this, i have used indexed="true" in a fields and the javascript function have been modified a litle (add a index):
<logic:iterate id="controles" name="listaejercicios" indexId="contador">
Contenido : <html:select name="controles" property="contenido" indexed="true" size="1"></html:select>
One problem: I need pass the index to javascript function. I can put:
<bean
efine id="INDX" name="contador"/>
but i can�t put: <%= INDX %>
<html:radio name="controles" property="tipocontenido" value="conindata" indexed="true" onclic="changeContenidosControl(this.value, <%= INDX %> );"/>Conducta
Well, we suppose the index value is passed good. This code generate the out:
Contenido : <select name="controles[0].contenido" size="1"></select>
<input type="radio" name="controles[0].tipocontenido" value="conindata" checked="checked" onclic="changeContenidosControl(this.value,0);">Conducta
<input type="radio" name="controles[0].tipocontenido" value="gesindata" onclic="changeContenidosControl(this.value,0);">Gesto
...........................
Contenido : <select name="controles[1].contenido" size="1"></select>
<input type="radio" name="controles[1].tipocontenido" value="conindata" checked="checked" onclic="changeContenidosControl(this.value,1);">Conducta
<input type="radio" name="controles[1].tipocontenido" value="gesindata" onclic="changeContenidosControl(this.value,1);">Gesto
Second problem: How do i declare the javascript function using a dinamic form?
function changeContenidosControl(control,i){
contenidosControl =
document.forms['controles'][i].contenido ??
document.forms['controldinamicoForm'][i].contenido ??
document.forms['controldinamicoForm'].controles[i].contenido ??
document.forms['controldinamicoForm'.controles[i]].contenido ??
document.forms[i].elements["controles["+ i +"].contenido"]; ??
...
Regards.