?
Solved

JS in Chrome

Posted on 2016-09-13
2
Medium Priority
?
73 Views
Last Modified: 2016-09-13
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>

Open in new window

0
Comment
Question by:mcrmg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 total points
ID: 41796296
I would recommend that you open Chrome's dev tool (F12) and inspect the Console tab for errors.  If something doesn't work, there is often an error.

If that doesn't lead you to your problem, I'd recommend that you give us a better idea of what action you're attempting, what you expect to occur, and what is actually happening instead.  Otherwise, we're just weeding through a huge chunk of code, looking for a needle in a haystack.
0
 

Author Closing Comment

by:mcrmg
ID: 41796372
thank you...I did not know the "F12 way"   I will give it a try
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question