• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2093
  • Last Modified:

can't get onchange to work in html:select tag

I have :
<html:select name="accion"  property="id_tipo_de_accion" onchange="accionSeleccionado(<%=iteration2 %>)" indexed="true">

The generated HTML is :
<select name="accion[0].id_tipo_de_accion" onchange="accionSeleccionado(<%=iteration2 %>)">


It's not translating the <%=iteration2 %> into its value.
What can I do?
0
supeno
Asked:
supeno
  • 4
  • 4
  • 4
1 Solution
 
gops1Commented:
If your generated html is this:

onchange="accionSeleccionado(<%=iteration2 %>)">

then it is wrong
0
 
gops1Commented:
probably you should not define anything insde the scriplet:

you can do either of the following:

to pass the object:
onchange="accionSeleccionado(this)">

to pass the value that you have selected then:
onchange="accionSeleccionado(this[this.selectedIndex].value)">
0
 
gops1Commented:
if you are passing the object:

onchange="accionSeleccionado(this)">

then your function is going to be like this:

function accionSeleccionado(o){
         //to access the value
         alert(o[o.selectedIndex].value);
        //to access the text
         alert(o[o.selectedIndex].text);
}
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
gops1Commented:
or try this way:
<%
String func= "accionSeleccionado(" + iteration2 + ");";
%>
<html:select name="accion"  property="id_tipo_de_accion" onchange="<%=func%>" indexed="true">

Open in new window

0
 
Michel PlungjanIT ExpertCommented:
or

<html:select name="accion"  property="id_tipo_de_accion" onchange="accionSeleccionado(${iteration2})" indexed="true">

perhaps?
0
 
supenoAuthor Commented:
I now have:

<c:set var="iteration2" value="${iteration2}"/>

onchange="accionSeleccionado('${iteration2}')"

But how do I increment the variable iteration2?

0
 
Michel PlungjanIT ExpertCommented:
what do you want to do

Tell us that instead of guessing how.

Perhaps we have a much better solution...
0
 
supenoAuthor Commented:
I want to dynamically alter the html layout of the page when the select box is changed. An ajax:select tag populates a second select box. Also, an extra text input or  a select may or may not be required depending on the result of the first select. To decide this I call a javascript function in onchange.
onchange="changePage('${iteration2}')"

I previously declare the variable iteration2 which identifies the row number : <c:set var="iteration2" value="1"/>

But don't know how to increment the variable.

0
 
Michel PlungjanIT ExpertCommented:
Hmm

Can't you identify what to do with the selected value or the index of it?

onChange="changePage(this)"

where in
function changePage(theSel) {
  alert('item #'+theSel.selectedIndex+':'+theSel.options[theSel.selectedIndex].value)
}

Michel
0
 
supenoAuthor Commented:
Yes, but I need an iteration number for the row ID anyway.
EL seems sweet, but how do I increment the variable?
<c:set var="iteration2" value="1"/>
0
 
supenoAuthor Commented:
<c:set var="iteration2" value="${iteration2+1}"/>

I was using an old tag library. Now it's OK.
0
 
Michel PlungjanIT ExpertCommented:
Ohh, that was too simple to consider :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now