Page 1 of 1

problem getting value from select

Posted: Tue Nov 17, 2009 9:15 pm
by yacahuma
I ahve the following code
var cellRightSel = row.insertCell(1);
var sel = document.createElement('select');
sel.id = 'filter_column_' + iteration;
sel.name = 'filter_column[]';// + iteration;
sel.options[0] = new Option('Municipio', 'Municipio');
sel.options[1] = new Option('Categoria', 'Categoria');
sel.options[2] = new Option('Zona', 'Zona');
sel.options[3] = new Option('Nivel de Ingreso', 'Nivel de Ingreso');
sel.options[4] = new Option('Vecindario', 'Vecindario');
sel.options[4] = new Option('Nivel de Transito', 'Nivel de Transito');
cellRightSel.align='center';
cellRightSel.onchange=function () {uploadValues(iteration)};
cellRightSel.appendChild(sel);

what I woul like to do is change the code to
cellRightSel.onchange=function () {uploadValues(this.value, iteration)}; //*****

Basically I want to get the value selected on cellRightSel and send it to the uploadValues function.

The problem is that I always get undefined

function uploadValues (val,num)
{
alert (val); //ALWAYSS UNDEFINED.
}


What am I doing wrong????

Re: problem getting value from select

Posted: Tue Nov 17, 2009 11:52 pm
by pcoder
You need to use:

Code: Select all

sel.onchange=function () {uploadValues(iteration)};
Instead of

Code: Select all

cellRightSel.onchange=function () {uploadValues(iteration)};
You are adding the onchange function on row element instead of select element..

Re: problem getting value from select

Posted: Wed Nov 18, 2009 4:03 am
by yacahuma
Thank pcoder, that was it. It was one of those thing that I could be stock forever.

Thank you