onChange IE?

O

oscar.redondo

Hi!

I want to create a "select" by Javascript with this function:

function cargaOpciones(iRow)
{
var i
var sel = document.createElement('select');

i=0
sel.name='propRow' + iRow;
sel.id='propRow' + iRow;
sel.onChange="alert('Change');";

while (i<document.forms[0].cboOpciones.options.length)
{
sel.options=new Option(i,i)

i=i+1;
}
return sel
}

Unfortunatelly, the onChange event is never fired? Anyone can help me?

Thanks in advance!
 
R

RobG

Hi!

I want to create a "select" by Javascript with this function:

function cargaOpciones(iRow)
{
var i
var sel = document.createElement('select');

i=0
sel.name='propRow' + iRow;
sel.id='propRow' + iRow;
sel.onChange="alert('Change');";

Javascript is case sensitive, even if HTML isn't - so use onchange.
And to satisfy a wider range of browsers, you need to assign a
function object or reference to the onchange property:

sel.onchange = function(){alert('Change');}


though using onchange with a select element has usability issues.
while (i<document.forms[0].cboOpciones.options.length)

That would be more efficient as:

var j = document.forms[0].cboOpciones.options.length;
while (i<j)

{
sel.options=new Option(i,i)

i=i+1;


Why not:

i++;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top