Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. javascript in listbox

javascript in listbox

Scheduled Pinned Locked Moved ASP.NET
javascript
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jayarajmrj
    wrote on last edited by
    #1

    function fnMoveItems(lstbxFrom,lstbxTo) { var varFromBox = document.all(lstbxFrom); var varToBox = document.all(lstbxTo); if ((varFromBox != null) && (varToBox != null)) { if(varFromBox.length < 1) { alert('There are no items in the source ListBox'); return false; } if(varFromBox.options.selectedIndex == -1) { alert('Please select an Item to move'); return false; } while ( varFromBox.options.selectedIndex >= 0 ) { var newOption = new Option(); newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text; newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value; varToBox.options[varToBox.length] = newOption; varFromBox.remove(varFromBox.options.selectedIndex); } } return false; } The above is my javascript code to move the values from one listbox to another. Once it move the values , the selected values are deleted from the sourceListbox(ie., left side listbox). Actually my task is , it never deletes the selected value . pls give the alternate code for it.

    P 1 Reply Last reply
    0
    • J jayarajmrj

      function fnMoveItems(lstbxFrom,lstbxTo) { var varFromBox = document.all(lstbxFrom); var varToBox = document.all(lstbxTo); if ((varFromBox != null) && (varToBox != null)) { if(varFromBox.length < 1) { alert('There are no items in the source ListBox'); return false; } if(varFromBox.options.selectedIndex == -1) { alert('Please select an Item to move'); return false; } while ( varFromBox.options.selectedIndex >= 0 ) { var newOption = new Option(); newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text; newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value; varToBox.options[varToBox.length] = newOption; varFromBox.remove(varFromBox.options.selectedIndex); } } return false; } The above is my javascript code to move the values from one listbox to another. Once it move the values , the selected values are deleted from the sourceListbox(ie., left side listbox). Actually my task is , it never deletes the selected value . pls give the alternate code for it.

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      I have modified your code, you can use it. function fnMoveItems(lstbxFrom,lstbxTo) { //var varFromBox = document.all(lstbxFrom); //var varToBox = document.all(lstbxTo); //You can access by list box id like //var varFromBox = document.getElementById('lstbxFromID'); //var varToBox = document.getElementById('lstbxToID'); if ((varFromBox != null) && (varToBox != null)) { if(varFromBox.length < 1) { alert('There are no items in the source ListBox'); return false; } if(varFromBox.options.selectedIndex == -1) { alert('Please select an Item to move'); return false; } var i; for(i=varFromBox.options.length-1;i>=0;i--) { if(varFromBox.options[i].selected) { var optn = document.createElement("OPTION"); optn.text = varFromBox.options[i].text; optn.value = varFromBox.options[i].value; lstbxTo.options.add(optn); varFromBox.remove(i); } } } return false; }

      Parwej Ahamad g.parwez@gmail.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups