Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-16
12
Medium Priority
?
2,086 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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 375 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)

664 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