Receiving a TypeError in FF and Chrome for JavaScript Function -
please help...i have tried correct error in firefox , chrome. receiving current error when run function. "typeerror: obj1.options not function". have tried many things including trying change onclick function jquery .click() function , placing between jquery document.ready function. works fine in ie, throws typeerror in other browsers. multiple type errors 1 addmember function , 1 remove member. may old deprecated javascript. offered appreciated. thanks
function removemember(idx, idx2){ //centralizes code remove selected items multiple select (listbox). //loops "backward" maintain valid indexing counters while removing items. var obj = idx; var obj2 = idx2; var ncount = 0; ncount = obj.options.length - 1; ( ncount; ncount > -1; ncount -- ) { if ( obj.options(ncount).selected == true ) { var ooption = document.createelement("option"); ooption.text = obj.options(ncount).text; ooption.value = obj.options(ncount).value; obj.options.remove(ncount); //jjk added add avail list obj2.add(ooption); } } //for //sort both listboxes sortoptions(obj2); sortoptions(obj); }
here complete html file can see all. have 2 list boxes , there 2 images click actions add or remove list items left first listset second listset.
<!-- #include file = "../include/permissions.inc" --> <!-- #include file = "../include/adovbs.inc" --> <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <% checkpermissions pmanagepfi, true dim stype, pfiname dim objsup, osrs, ret, isupid stype = request.querystring ("type") pfid = request.form ("pfid") 'set type if stype = "sv" stype = "2" elseif stype = "dc" stype = "1" end if 'get pfi name if not pfid = "" set objpfi = server.createobject("las.net.cpfi") pfiname = objpfi.getname(clng(pfid)) set objpfi=nothing end if function seloptions() response.write "<option value='0'>select</option>" if stype = "2" response.write "<option selected value='2'>servicer</option>" else response.write "<option value='2'>servicer</option>" end if if stype = "1" response.write "<option selected value='1'>document custodian</option>" else response.write "<option value='1'>document custodian</option>" end if end function function getsupporters() set objsup = server.createobject("las.net.csupporter") dim ssupportname, gettype if stype = "2" gettype = "servicer" elseif stype = "1" gettype = "document custodian" end if ret = objsup.getsupportlist(cstr(gettype), clng(pfid)) set osrs = unpersistrs(ret) if not osrs.eof then osrs.movefirst osrs.filter = "bactive = true" do while not osrs.eof ssupportname = osrs.fields("ssupport_name").value isupid = osrs.fields("isupport_id").value response.write "<option value='" & isupid & "'>" & ssupportname & "</option>" osrs.movenext loop end if set osrs=nothing set objsup=nothing end function function getpfisupporters() if not pfid = "" then set objpfi = server.createobject("las.net.cpfi") dim osrs if stype="2" ret = objpfi.getsupporters("servicer",clng(pfid)) elseif stype= "1" ret = objpfi.getsupporters("document custodian",clng(pfid)) end if if len(ret) <> 0 set osrs = unpersistrs(ret) if not osrs.eof then do while not osrs.eof ssupportname = osrs.fields("ssupport_name").value isupid = osrs.fields("isupport_id").value response.write "<option value='" & isupid & "'>" & ssupportname & "</option>" osrs.movenext loop end if end if set osrs=nothing set objpfi=nothing end if end function%> <title>fhlb</title> <script language="javascript"> function selectvalue(idx, val){ //centralizes code loop index values in select , highlight //appropriate item. var obj = idx; var ncount = 0; var ncounter = 0; ncount = obj.options.length; for ( ncounter = 0; ncounter < ncount; ncounter ++ ) { if ( obj.options(ncounter).value == val ) { obj.selectedindex = ncounter; } } obj.value = obj.options( obj.selectedindex ).value ; } function oneselected(idx){ //function search fieldset, , determine whether checkboxes //have been selected. var orows = idx.children(0).children(0).children //the child of fieldset table. var ncount = idx.children(0).children(0).children.length; var ncounter = 0; var ret = false; for ( ncounter = 0; ncounter < ncount; ncounter ++ ) { if ( orows(ncounter).children(1).children(0).checked == true ) { ret = true; break; } } if ( ret == true ){ return true; } else{ return false; } } function validate() { //alert("attempted save"); var obj = document.frmfhlbglobal.memberlist ; var ncount = 0; var ncounter = 0; ncount = obj.options.length; for ( ncounter = 0; ncounter < ncount; ncounter ++ ) { obj.options(ncounter).selected = true; } document.frmfhlbglobal.action="process_assignsupporter.asp"; document.frmfhlbglobal.submit(); } function refresh() { var obj = document.all.seltype; obj.value = obj.options( obj.selectedindex ).value; document.frmfhlbglobal.action = "assignsupporter.asp?type=" + obj.value; document.frmfhlbglobal.submit(); } function addmember(idx1, idx2){ //centralizes code loop index values in select , highlight //appropriate item. var obj1 = idx1; var obj2 = idx2; var ncount1 = 0; var ncounter1 = 0; var ncount = 0; //add entries assigned box ncount1 = obj1.options.length; for ( ncounter1 = 0; ncounter1 < ncount1; ncounter1 ++ ) { if ( obj1.options(ncounter1).selected == true ) { var ooption = document.createelement("option"); ooption.text = obj1.options(ncounter1).text; ooption.value = obj1.options(ncounter1).value; obj2.add(ooption); } } //remove entries available box //loops "backward" maintain valid indexing counters while removing items. ncount = obj1.options.length - 1; for ( ncount; ncount > -1; ncount -- ) { if ( obj1.options(ncount).selected == true ) { obj1.options.remove(ncount); } } //sort both listboxes sortoptions(obj2); sortoptions(obj1); } function removemember(idx, idx2){ //centralizes code remove selected items multiple select (listbox). //loops "backward" maintain valid indexing counters while removing items. var obj = idx; var obj2 = idx2; var ncount = 0; ncount = obj.options.length - 1; for ( ncount; ncount > -1; ncount -- ) { if ( obj.options(ncount).selected == true ) { var ooption = document.createelement("option"); ooption.text = obj.options(ncount).text; ooption.value = obj.options(ncount).value; obj.options.remove(ncount); //jjk added add avail list obj2.add(ooption); } } //for //sort both listboxes sortoptions(obj2); sortoptions(obj); } //jjk sort add v2.3.2 function sortoptions(listbox) { //get listbox values arrays var arrvalues = new array() var arrtext = new array() var obj = listbox; var ncount = 0; var ncounter = 0; ncount = obj.options.length; for ( ncounter = 0; ncounter < ncount; ncounter ++ ) { arrtext[ncounter]= obj.options(ncounter).text; arrvalues[ncounter] = obj.options(ncounter).value; } var x, y, holder, temp_text1, temp_text2; // bubble sort method. for(x = 0; x < arrtext.length; x++) { for(y = 0; y < (arrtext.length-1); y++) { temp_text1 = arrtext[y]; temp_text2 = arrtext[y+1]; if(temp_text1.touppercase() > temp_text2.touppercase()) { holder = arrtext[y+1]; arrtext[y+1] = arrtext[y]; arrtext[y] = holder; //do same values array keep indexes holder = arrvalues[y+1]; arrvalues[y+1] = arrvalues[y]; arrvalues[y] = holder; } } } // update select box list. var i; for(i = 0; < arrvalues.length; i++) { if(listbox.options[i] == null) { var ooption = document.createelement("option"); ooption.text = arrtext[i]; ooption.value = arrvalues[i]; listbox.options[i] = ooption; } else { listbox.options[i].text = arrtext[i]; listbox.options[i].value = arrvalues[i]; } } } //jjk sort end function gopfi(){ document.frmfhlbglobal.action ="viewpfi.asp"; document.frmfhlbglobal.submit(); } </script> <link rel="stylesheet" type="text/css" href="../style/<%=application("districtcode")%>.css"> </head> <body> <!-- #include file = "../include/head.inc" --> <p> <table align="center" valign="middle" width="50%" border="1" class="innertable"> <tr> <td class="tableheader" width="100%"> <center><font class="tableheadertitletext">add supporter <%=pfiname%></font></center> </td> </tr> <tr><td align="center"> <form name="frmfhlbglobal" method="post" action="process_assignsupporter.asp"> <input type="hidden" name="pfid" value="<%=pfid%>"> <table width="100%" cellpadding="0" cellspacing="0"> <input type="hidden" name="test"> <tr> <td align="center"> <fieldset><!------list name , type--------> <table class="innertable" width="100%" border="0"> <tr> <td class="innertabletextsmall"> <b>list type:</b> <select name="seltype" onchange="refresh()"> <%=seloptions%> </select> </td> </tr> </table> </fieldset> <fieldset><!------listbox select--------> <table class="innertable" width="100%" border="0"> <tr> <td width="45%" align="center" class="innertabletextsmall"> <b>available<b><br> <select name="mainlist" multiple style="width: 200" size="15" ondblclick="addmember(document.frmfhlbglobal.mainlist, document.frmfhlbglobal.memberlist);"> <% 'if len(trim(stroptions)) > 0 response.write getsupporters() 'end if %> </select> </td> <td width="10%" align="center" valign="middle"> <img src="../images/<%=application("districtcode")%>/add2.gif" name="add member(s)" id="add" onclick="addmember(document.frmfhlbglobal.mainlist, document.frmfhlbglobal.memberlist);"> <img src="../images/<%=application("districtcode")%>/remove.gif" name="remove member(s)" id="remove" onclick="removemember(document.frmfhlbglobal.memberlist, document.frmfhlbglobal.mainlist);"> </td> <td width="45%" align="center" class="innertabletextsmall"> <b>currently assigned<b><br> <select name="memberlist" multiple style="width: 200" size="15" ondblclick="removemember(document.frmfhlbglobal.memberlist);"> <%=getpfisupporters()%> </select> </td> </tr> </table> </fieldset> <fieldset> <table class="innertable" width="100%" border="0"> <tr> <td align="center"> <img src="../images/<%=application("districtcode")%>/save.gif" name="save" id="save" onclick="validate()"> <img src="../images/<%=application("districtcode")%>/cancel.gif" name="cancel" id="cancel" onclick="gopfi()"> </td> </tr> </table> </fieldset> </td> </tr> </table> </td> </tr> </table> <input type="hidden" name="stype" value="<%=stype%>"> </form> <!-- #include file = "../include/foot.inc" --> </body> </html>
obj.options(ncount)
should be
obj.options[ncount]
obj
htmlselectelement
object. htmlselectelement
doesn't have options
method, following incorrect:
obj.options(ncount) // xxx
htmloptionscollection
objects have options
property, documented follows:
returns
htmloptionscollection
containing set of<option>
elements contained element.
htmloptionscollection
has 2 methods:
item(index)
- returns specific node @ given zero-based index (gives null if out of range)nameditem(name)
- returns specific node given domstring (i.e., string) id. returns null if no such named node exists.
that means should using
obj.options.item(ncount)
htmloptionscollection
's parent class says
in javascript, code accesses
htmlcollection
object, in order item of givenhtmlcollection
, square bracket syntax can used instead of directly callingitem()
ornameditem()
methods. numeric values in square brackets work same wayitem()
, string values work same waynameditem()
.
that means using
obj.options[ncount]
Comments
Post a Comment