| Author |
Iterate indexId + Indexed Form + Javascript
|
Manuel Sanchez Iba�ez
Greenhorn
Joined: Jul 12, 2005
Posts: 20
|
|
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.
|
 |
Daniel Durette
Greenhorn
Joined: Jan 25, 2006
Posts: 1
|
|
I faced the same proble today and here is the solution is used: <script language="Javascript"> function clickCheckbox(index) { var checkboxName = "warranty[" + index + "].selected"; var checkbox = document.getElementById(checkboxName); checkbox.checked = true; } </script> <% int index = 0; %> //before the start of your iterator in the jsp inside your iterator: <% StringBuffer jsMethod = new StringBuffer(); jsMethod.append("clickCheckbox("); jsMethod.append(index); jsMethod.append(");"); String jsString = jsMethod.toString(); %> ... <html:checkbox name="warranty" property="selected" indexed="true"/> <html:text name="warranty" property="amount" indexed="true" onchange="<%= jsString %>"/> ... <% index++; %> If you have further questions, please reply to this post.
Originally posted by Manuel Sanchez Iba�ez: 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.
|
 |
Manuel Sanchez Iba�ez
Greenhorn
Joined: Jul 12, 2005
Posts: 20
|
|
|
Thank you very much for your answer.
|
 |
 |
|
|
subject: Iterate indexId + Indexed Form + Javascript
|
|
|