Solved

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

Posted on 2007-11-16
12
2,081 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Rhino Java Array in Javascript 1 30
Asp response.write to clients 6 32
Bootstrap question 4 26
How do I add counter to html listbox using jquery 2 22
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

685 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