Solved

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

Posted on 2007-11-16
12
2,072 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to implement Singleton Design Pattern in Java.
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)

706 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

15 Experts available now in Live!

Get 1:1 Help Now