Greywacke Posted May 20, 2010 Share Posted May 20, 2010 hi there,i keep getting the following error when trying to parse the array if there is only one 2nd level element. Error: arr[3] is undefinedSource File: http://www.ferrety.co.za/fab/scripts/ajax_prices.jsLine: 454the function is below, line 454 marked in bold:function addservices(arr) { var sel = document.getElementById("menu_service"); var sel = new Array(); for (i = 0; i < arr.length; i++) { if (arr[i][2]) { // dynamicaly create dropdowns for this services attribute combination, setting accesskey and tabindexes var lyr = document.getElementById("div_combination"); var p = lyr.firstChild; var sel = new Array(); var lbl = new Array(); [b]for (n = 0; n < arr[3].length; n++) {[/b] var lbl = document.createElement("label"); var sel = document.createElement("select"); lbl.setAttribute("for", arr[3][n][0]); sel.setAttribute("name", "valuecombo["+arr[3][n][0]+"]"); sel.setAttribute("id", "valuecombo["+arr[3][n][0]+"]"); var opt = document.createElement("option"); opt.text = "* Select " + lbl[n]; // dropdown description as text opt.value = "0"; // 0 as value opt.selected = true; try { sel.add(opt, null); // standards compliant; doesn't work in IE } catch(ex) { sel.add(opt); // IE only } for (var o = 2; o < arr[3][n].length; o++) { var optdata = arr[3][n][o].split(";.;"); var opt = document.createElement("option"); opt.text = optdata[1]; // attribute value as text opt.value = optdata[0]; // attribute value id as value try { sel.add(opt, null); // standards compliant; doesn't work in IE } catch(ex) { sel.add(opt); // IE only } } p.appendChild(lbl); p.appendChild(sel); } } var opt = document.createElement('option'); opt.text = arr[i][1]; // service description opt.value = collapse(arr[i]); // save array as value opt.selected = (arr[i][2])?true:false; // selected option try { sel.add(opt, null); // standards compliant; doesn't work in IE } catch(ex) { sel.add(opt); // IE only } }} there is supposed to be support for multiple services, though at this stage there is only one. the multidimentional array is as follows, with ;;;; being primary seperators, ;;; secondary seperators: // get services information var services = xmldoc.getElementsByTagName("services"); for (var r = 0; r < services.length; r++) { var i = 0; var arr = new Array(); for (var s = 0; s < services[r].childNodes.length; s++) { var svc = services[r].childNodes[s]; if (svc.nodeName == "service" && svc.attributes) { arr[i] = new Array(); for (var a = 0; a < svc.attributes.length; a++) { arr[i][a] = svc.attributes[a].value; } for (var b = 0; b < svc.childNodes.length; b++) { var sel = svc.childNodes[b]; var z = arr[i].length; if (sel.attributes) { arr[i][z] = new Array(); for (var d = 0; d < sel.attributes.length; d++) { arr[i][z][d] = sel.attributes[d].value; } } } i++; } } //salert(arrs); addservices(arr); } any help would be greatly appreciated! Link to comment Share on other sites More sharing options...
Greywacke Posted May 20, 2010 Author Share Posted May 20, 2010 oh! i forgot completely about the top level array!that line should be: for (n = 0; n < arr[i][3].length; n++) { issue resolved Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.