Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   onChange IE? (http://www.velocityreviews.com/forums/t933091-onchange-ie.html)

oscar.redondo@gmail.com 10-04-2007 06:06 AM

onChange IE?
 
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[i]=new Option(i,i)

i=i+1;
}
return sel
}

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

Thanks in advance!


RobG 10-04-2007 12:29 PM

Re: onChange IE?
 
On Oct 4, 4:06 pm, oscar.redo...@gmail.com wrote:
> 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[i]=new Option(i,i)
>
> i=i+1;


Why not:

i++;



--
Rob



All times are GMT. The time now is 03:37 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57