javascript - isolating specific values in external .js array -



javascript - isolating specific values in external .js array -

i'm trying populate selection list external javascript array. works i'm trying populate values using id column, failing. i'm using check-boxes , 'if' statement see box checked, , populate appropriate array values based on selection. i'm using 'if' within loop match id value in array, , add together matching values selection. however, seems disregarding status , reading entire array in selection list. obvious error code novice.

function populateislandlist () {

var form = document.forms["island_form"]; var islands = form.islands; if (islands[0].checked){alert("works"); (i = 0; < pislands.length; i++) if (pislands[i][1] = 1){ document.forms["location"].islands.options[i] = new option(pislands[i][0], i)}}; if (islands[1].checked){alert("works"); (i = 0; < pislands.length; i++) if (pislands[i][1] = 2){ document.forms["location"].islands.options[i] = new option(pislands[i][0], i)}}; }

your first error here:

var islands = document.getelementbyid("island_form");

document.getelementbyid() returns single dom element, not list of objects. so, islands[0] , islands[1] going undefined , islands[0].checked create script error.

you can have 1 dom element given id. can have multiple elements class name maybe should switch using class names , using document.getelementsbyclassname("something")

fyi, should looking in browser error console or debug console see script errors should have given indication of problem here.

javascript arrays if-statement

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -