Solved

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

Posted on 2007-11-16
12
2,077 Views
Last Modified: 2013-11-24
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
Comment
Question by:supeno
  • 4
  • 4
  • 4
12 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20297667
If your generated html is this:

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

then it is wrong
0
 
LVL 17

Expert Comment

by:gops1
ID: 20297673
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
 
LVL 17

Expert Comment

by:gops1
ID: 20297677
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 17

Expert Comment

by:gops1
ID: 20297726
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 20298083
or

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

perhaps?
0
 

Author Comment

by:supeno
ID: 20298101
I now have:

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

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

But how do I increment the variable iteration2?

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20298212
what do you want to do

Tell us that instead of guessing how.

Perhaps we have a much better solution...
0
 

Author Comment

by:supeno
ID: 20311240
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20311378
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
 

Author Comment

by:supeno
ID: 20311462
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
 

Author Comment

by:supeno
ID: 20311505
<c:set var="iteration2" value="${iteration2+1}"/>

I was using an old tag library. Now it's OK.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20311877
Ohh, that was too simple to consider :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now