www.webdeveloper.com
Results 1 to 3 of 3

Thread: removeMe() Function does not work

  1. #1
    Join Date
    Jan 2007
    Posts
    164

    removeMe() Function does not work

    RemoveME function removes more than one item when populating the select fields from the user input feilds instead of the select fields.


    Code:
    
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    
    <!-- Begin
    function moveOver()  
    {
    var boxLength = document.choiceForm.choiceBox.length;
    var selectedItem = document.choiceForm.available.selectedIndex;
    var selectedText = document.choiceForm.available.options[selectedItem].text;
    var selectedValue = document.choiceForm.available.options[selectedItem].value;
    var i;
    var isNew = true;
    if (boxLength != 0) {
    for (i = 0; i < boxLength; i++) {
    thisitem = document.choiceForm.choiceBox.options[i].text;
    if (thisitem == selectedText) {
    isNew = false;
    break;
          }
       }
    } 
    if (isNew) {
    newoption = new Option(selectedText, selectedValue, false, false);
    document.choiceForm.choiceBox.options[boxLength] = newoption;
    }
    document.choiceForm.available.selectedIndex=-1;
    }
    function removeMe() {
    var boxLength = document.choiceForm.choiceBox.length;
    arrSelected = new Array();
    var count = 0;
    for (i = 0; i < boxLength; i++) {
    if (document.choiceForm.choiceBox.options[i].selected) {
    arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
    }
    count++;
    }
    var x;
    for (i = 0; i < boxLength; i++) {
    for (x = 0; x < arrSelected.length; x++) {
    if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
    document.choiceForm.choiceBox.options[i] = null;
       }
    }
    boxLength = document.choiceForm.choiceBox.length;
       }
    }
    
    
    function reshow() {
    
        whatTo = document.choiceForm.elements.choiceBox;
        for (var i = whatTo.length;i > 0;i--)
            whatTo.options[0] = null;
    	if (document.choiceForm.manual4.value != '') {
        showLink();
        }
        else {}
    }
    
    function showLink() {
    
            opt(document.choiceForm.manual0.value);
            opt(document.choiceForm.manual1.value);
            opt(document.choiceForm.manual2.value);
            opt(document.choiceForm.manual3.value);
    }
    
    function opt(text) {
        var optionName = new Option(text)
        var length = whatTo.length;
        whatTo.options[length] = optionName;
    }
    
    //  End -->
    </script>
    
    </HEAD>
    
    
    <BODY>
    
    <center>
    <form name="choiceForm">
    
    <table border=0>
    <tr>
    <td valign="top" width=175>
    Available Content:
    <br>
    <select name="available" size=10 onchange="moveOver();">
    <option value=1>Company News
    <option value=2>Industry News
    <option value=3>Product Updates
    </select>
    </td>
    <td valign="top">
    Your Choices:
    <br>
    <select name="choiceBox" style="width:150;" size="10" onchange="removeMe();">
    </select>
    </td>
    </tr>
    <tr>
    <td colspan=2 height=10>
    
    </td>
    </tr>
    </table>
    <input type="button" value="Get Selected Values" onclick="reshow();">
    <input type="text" value="Company News" name="manual0">
    <input type="text" value="Industry News" name="manual1">
    <input type="text" value="Product Updates" name="manual2">
    <input type="text" value="Help Me" name="manual3">
    <input type="hidden" value=w34 name="manual4">
    </form>
    </center>

  2. #2
    Join Date
    Feb 2003
    Posts
    85
    Try this:
    for (i = 0; i < boxLength; i++) {
    if (document.choiceForm.choiceBox.options[i].selected) {
    arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
    count++;
    }
    }

    skriptor

  3. #3
    Join Date
    Jan 2007
    Posts
    164
    Still does the exact thing.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles