problem getting value from select

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

problem getting value from select

Post 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????
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: problem getting value from select

Post 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..
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: problem getting value from select

Post by yacahuma »

Thank pcoder, that was it. It was one of those thing that I could be stock forever.

Thank you
Post Reply