troubleshooting Question

JS in Chrome

Avatar of mcrmg
mcrmg asked on
JavaScript
2 Comments1 Solution128 ViewsLast Modified:
Hi,

I was wondering if EEs could let me know this code only works in IE but Chrome.  Is there anything I need to tweak?  thanks


<form name="form1" method="post">


	

<TABLE border = "1" width="910"  class="bankth">
	    <tr>

		    <td colspan=2>&nbsp;</td>
		    
		    <td colspan=2>&nbsp;</td>
	    </tr> 
		<TR>

			<TD width=250>

			<SELECT multiple size="7" name="testCategory" CLASS="AdHoc_Form_LEFT"> 
			      <option value="volvo">Volvo</option>
                  <option value="saab">Saab</option>
                  <option value="mercedes">Mercedes</option>
                  <option value="audi">Audi</option>
			</SELECT> 
			</TD>
			<TD width=30>
			    <INPUT onclick=AddElement(this.form); type=button value=" > "><BR>
			</TD>
		
			<TD width=125 align=center>
				Move All Categories
				<INPUT style="WIDTH: 30px" onclick=AddAllElements(this.form); type=button value=">>"><BR>
				<INPUT style="WIDTH: 30px" onclick=RemoveAllElements(this.form); type=button value="<<"><BR>
			</TD>
			<TD  width=250 valign=bottom>
				<SELECT  CLASS="AdHoc_Form_RIGHT" multiple size=17 name=mainlist></SELECT> 
			</TD>
			<TD  width=240>
			    Change Columns Order<br />
				<INPUT onclick=MoveUp(this.form) type=button value="    Move Up   "><br>
				<INPUT onclick=MoveDown(this.form) type=button value=" Move Down "> 
			</TD>     		
			
		</TR>

</TABLE>
</form>
            






        
<SCRIPT>    var row = 500;
    var countElements = 0;
    var totalLists = 10;
    var indexArray = new Array((totalLists + 1));
    var lArray = new Array(row);
    InitializeArrays();
    if ('<%=request.QueryString("save")%>' == 1)
        AddSavedElements(document.form1);
    function InitializeArrays() {
        j = 0;
        for (var i = 0; i < document.form1.elements.length; i++) {
            if (document.form1.elements(i).type == "select-multiple") {
                lname = document.form1.elements(i).name;
                listObj = FindList(document.form1, lname);
                indexArray[j] = new Array();
                indexArray[j][0] = listObj.length;
                indexArray[j][1] = lname;
                j++;
            }
        }
        for (var i = 0; i < row; i++)
            lArray[i] = new Array();
    }
    
    function AddElement(frm) {
        if (!isSelected(frm, "l"))
            alert("You must select an item from at least one pannel on the left side.");
        else {
            var eArray = new Array();
            var tArray = new Array();
            //looks for all the selects on the left side that contains selected items
            for (var i = frm.elements.length - 1; i >= 0; i--) {
                if (frm.elements(i).type == "select-multiple" && frm.elements(i).name != "mainlist") {
                    //once the select is found then it will go through all the selected items
                    //within the select and delete them from bottom to top
                    for (var j = frm.elements(i).length - 1; j >= 0; j--) {
                        if (frm.elements(i).options[j].selected) {
                            value = frm.elements(i).options[j].value;
                            text = frm.elements(i).options[j].text;
                            eArray[countElements] = value;
                            tArray[countElements] = text;
                            if (!isInArray(value, lArray)) {
                                lArray[countElements][0] = frm.elements(i).options[j].value;
                                lArray[countElements][1] = frm.elements(i).name;
                                lArray[countElements][2] = 1;
                                lArray[countElements][3] = frm.elements(i).options[j].text;
                            }
                            RemoveOption(frm.elements(i), j);
                            DecrementIndexes(frm.elements(i).name);
                            countElements++;
                        }
                    }
                }
            }
            for (var j = eArray.length - 1; j >= 0; j--) {
                if (eArray[j] != null) {
                    AddOption(frm.mainlist, eArray[j], tArray[j]);
                    eArray[j] = null;
                    tArray[j] = null;
                    IncrementIndexes("mainlist");
                }
            }
        }
    }
    function AddListElements(frm, list) {
        if (list.length != 0) {
            var eArray = new Array();
            var tArray = new Array();
            //looks for all the selects on the left side that contains selected items
            for (var j = list.length - 1; j >= 0; j--) {
                value = list.options[j].value;
                text = list.options[j].text;
                eArray[countElements] = value;
                tArray[countElements] = text;
                if (!isInArray(value, lArray)) {
                    lArray[countElements][0] = list.options[j].value;
                    lArray[countElements][1] = list.name;
                    lArray[countElements][2] = 1;
                    lArray[countElements][3] = list.options[j].text;
                }
                RemoveOption(list, j);
                DecrementIndexes(list.name);
                countElements++;
            }
            for (var j = eArray.length - 1; j >= 0; j--) {
                if (eArray[j] != null) {
                    AddOption(frm.mainlist, eArray[j], tArray[j]);
                    eArray[j] = null;
                    tArray[j] = null;
                    IncrementIndexes("mainlist");
                }
            }
        }
    }
    function AddAllElements(frm) {
        for (var i = 0; i < frm.elements.length; i++) {
            if (frm.elements(i).type == "select-multiple" && frm.elements(i).name != "mainlist") {
                AddListElements(frm, frm.elements(i));
            }
        }
    }
    function RemoveElement(frm) {
        if (!isSelected(frm, "r"))
            alert("You must select at least one item from the right side.");
        else {
            for (var j = frm.mainlist.length - 1; j >= 0; j--) {
                if (frm.mainlist.options[j].selected) {
                    setArray(frm.mainlist.options[j].value);
                    RemoveOption(frm.mainlist, j);
                    DecrementIndexes("mainlist");
                }
            }
            for (var j = lArray.length - 1; j >= 0; j--) {
                if (lArray[j][2] == 2) {
                    indexList = FindElement(lArray[j][0]);
                    list = FindList(frm, lArray[indexList][1]);
                    if (!optionExists(list, lArray[j][0])) {
                        AddOption(list, lArray[indexList][0], lArray[indexList][3]);
                        IncrementIndexes(list.name);
                    }
                    lArray[j][2] = 1;
                }
            }
        }
    }
    function RemoveListElements(frm, list) {
        if (frm.mainlist.length != 0) {
            for (var j = frm.mainlist.length - 1; j >= 0; j--) {
                if (inList(frm.mainlist.options[j].value, list)) {
                    setArray(frm.mainlist.options[j].value);
                    RemoveOption(frm.mainlist, j);
                    DecrementIndexes("mainlist");
                }
            }
            for (var j = lArray.length - 1; j >= 0; j--) {
                if (lArray[j][2] == 2) {
                    indexList = FindElement(lArray[j][0]);
                    list = FindList(frm, lArray[indexList][1]);
                    if (!optionExists(list, lArray[j][0])) {
                        AddOption(list, lArray[indexList][0], lArray[indexList][3]);
                        IncrementIndexes(list.name);
                    }
                    lArray[j][2] = 1;
                }
            }
        }
    }
    function RemoveAllElements(frm) {
        for (var i = 0; i < frm.elements.length; i++) {
            if (frm.elements(i).type == "select-multiple" && frm.elements(i).name != "mainlist") {
                RemoveListElements(frm, frm.elements(i));
            }
        }
    }
    function MoveUp(frm) {
        for (var i = 0; i < frm.mainlist.length; i++) {
            if (frm.mainlist.options[i].selected) {
                SwapUp(frm, i);
            }
        }
    }
    function SwapUp(frm, sIndex) {
        i = sIndex;
        if (i > 0) {
            value1 = frm.mainlist.options[i].value;
            value2 = frm.mainlist.options[i - 1].value;
            text1 = frm.mainlist.options[i].text;
            text2 = frm.mainlist.options[i - 1].text;
            option = new Option(text2, value2);
            frm.mainlist.options[i] = option;
            option = new Option(text1, value1);
            frm.mainlist.options[i - 1] = option;
            frm.mainlist.options[i - 1].selected = true;
        }
        if (i == 1)
            frm.mainlist.options[i - 1].selected = false;
    }
    function MoveDown(frm) {
        for (var i = frm.mainlist.length - 1; i >= 0; i--) {
            if (frm.mainlist.options[i].selected) {
                SwapDown(frm, i);
            }
        }
    }
    function SwapDown(frm, sIndex) {
        i = sIndex;
        if (i < frm.mainlist.length - 1) {
            value1 = frm.mainlist.options[i].value;
            value2 = frm.mainlist.options[i + 1].value;
            text1 = frm.mainlist.options[i].text;
            text2 = frm.mainlist.options[i + 1].text;
            option = new Option(text2, value2);
            frm.mainlist.options[i] = option;
            option = new Option(text1, value1);
            frm.mainlist.options[i + 1] = option;
            frm.mainlist.options[i + 1].selected = true;
        }
        if (i == frm.mainlist.length - 2)
            frm.mainlist.options[i + 1].selected = false;
    }
    function isInArray(value, Array) {
        var inArray = false;
        for (var i = 0; i < Array.length && !inArray; i++) {
            if (Array[i][0] == value)
                inArray = true;
        }
        return inArray;
    }
    function inList(value, list) {
        found = false;
        for (var i = 0; i < lArray.length && !found; i++) {
            if (lArray[i][0] == value && lArray[i][1] == list.name)
                found = true;
        }
        return found;
    }
    function optionExists(list, value) {
        var found = false;
        for (var i = 0; i < list.length; i++)
            if (list.options[i].value == value)
            found = true;
        return found;
    }
    function setArray(value) {
        found = false;
        for (var i = 0; i < lArray.length; i++) {
            if (lArray[i][0] == value) {
                lArray[i][2] = 2;
                found = true;
            }
        }
    }
    function AddOption(list, value, text) {
        //Option("TheText","TheValue")
        option = new Option(text, value);
        var index = getIndex(list);
        list.options[index] = option;
    }
    function RemoveOption(list, index) {
        list.options[index] = null;
    }
    //Returns an object that references to the select element within the form
    function FindList(frm, name) {
        var found = false;
        var listObject = null;
        for (var i = 0; i < frm.elements.length && !found; i++) {
            if (frm.elements(i).name == name) {
                listObject = frm.elements(i);
                found = true;
            }
        }
        return listObject;
    }
    //Returns the index of the element moved to the right pannel
    function FindElement(key) {
        var found = false;
        var j = 0;
        for (var i = countElements - 1; i >= 0 && !found; i--)
            if (lArray[i][0] == key) {
            j = i;
            found = true;
        }
        return j;
    }
    function isSelected(frm, opt) {        
        var selected = false;
        if (opt == "l") {

            for (var i = 0; i < frm.elements.length && !selected; i++) {
                 
                if (frm.elements(i).type == "select-multiple" && frm.elements(i).name != "mainlist") {
                    if (frm.elements(i).value != "")
                        selected = true;
                    
                }
                
            }
        }
        else {
            
	    if (frm.mainlist.value != "") {
	        selected = true;
	    }	
	}

	return selected;
}

function IncrementIndexes(lname)
{
	found = false;
	for(var i = 0 ; i < indexArray.length && !found ; i++)
		if(indexArray[i][1] == lname )
		{
			indexArray[i][0]++;
			found = true;
		}
}

function DecrementIndexes(lname)
{
	found = false;
	for(var i = 0 ; i < indexArray.length && !found ; i++)
		if(indexArray[i][1] == lname )
		{
			indexArray[i][0]--;
			found = true;
		}
}

function getIndex(lname)
{
	found = false;
	var index = 0;
	for(var i = 0 ; i < indexArray.length && !found ; i++)
	{
		if(indexArray[i][1] == lname.name )
		{
			index=indexArray[i][0];
			found = true;
		}
	}
	return index;
}

function DisplayArray()
{
	empty = true;
	for(var i=0;i<lArray.length && lArray[i][0] != undefined ;i++)
	{
		document.write(i + " " + lArray[i][0] + " " + lArray[i][1] + " " + lArray[i][2] + " " + lArray[i][3] + "<br>");
		empty = false;
	}
	
	if (empty)
		alert("Array is empty");
}

function SendValues(frm)
{
	if ( frm.mainlist.length == 0 )
		alert("There is no fields to be displayed");
	else
	{
		listvalue = new String();
		listvalue = "";
		listdesc = new String();
		listdesc = "";
		listcat = new String();
		listcat = "";
		for(var i = 0; i < frm.mainlist.length ; i++)
		{
			listval = frm.mainlist.options[i].value;
			value = listval.substring(0,listval.indexOf(":"));
			cat = listval.substring(listval.indexOf(":")+1,listval.length);
			
			listvalue = listvalue + value + ",";
			listcat = listcat + cat + ",";
			listdesc = listdesc + frm.mainlist.options[i].text + ",";
		}
		
		listvalue = listvalue.substring(0,listvalue.length-1);
		frm.fieldlistvalue.value = listvalue;

		listcat = listcat.substring(0,listcat.length-1);
		frm.fieldlistcat.value = listcat;

		listdesc = listdesc.substring(0,listdesc.length-1);
		frm.fieldlistdesc.value = listdesc;

		
		frm.submit();
		
	}
}

function LoadReport(frm)
{
	if ( frm.SavedReports.value != "" )
	{
		frm.action = "adhocReportCol.asp?save=1";
		frm.SavedReportID.value = frm.SavedReports.value;
		frm.submit();
	}
	else
	{
		frm.action = "adhocReportCol.asp?ScrSt=1";
		frm.submit();
	}
}
</SCRIPT>

       
<!--Close Progressbar window-->
<script language="JavaScript" src="js/closeProgressbar.js"></script>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros