Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simplified: How to pass selections to Textarea?

    My problem is shown on this page. I have a combo box, and what I need is for the selections the user makes (into List 2) to be written into the textarea below the lists (don't ask why.)

    So for example, if the user moves Alaska and Colorado into List 2, those 2 states would be written into the textarea below the lists.

    I have a simple function selectAll() attached to the SAVE button which (unsurprisingly) when pressed selects all the items in List 2 .
    Code:
    function selectAll(box) {
         for(var i=0; i<box.length; i++) {
         	box[i].selected = true;
         }
    }
    It is called just using this:
    Code:
    <input type="button" name="submit_button" value="SAVE" onClick="selectAll(document.combo_box.list2);">
    Also, it doesn't matter to me if the State names are written to the textarea as they are moved between Lists, or if they are moved as a group at the end by the user pressing SAVE.

    Can anyone help me with this (pretty please.) How do I get the selected States to be written into the Textarea?

    thanksmuch.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hmmmm

    Forgive me if I'm asking silly questions, but why not just iterate through the items at the end of to list which you seem to be doing already several times in function move() and add all the items to the textarea once the sort functions have done that bit for you...?

    textareaobj.innerHTML = item[0].text += "<br>" + item[1].text etc...

    You only want the items in the from select to be added to the list or sth?

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I only want the items in the in the right hand select, List 2, to be added to the textarea.

    I added this to function, setTboxValue(), to the buttons' onClick event handler, so it becomes :

    onClick="selectAll(document.comboBox.list2); setTboxValue(document.comboBox.list2);"

    And the function setTboxValue() is
    Code:
    function setTboxValue(box){
    
    	for(var i=0; i<box.length; i++) {
    		var selectedItem = box[i].selectedIndex;
    		var selectedItemText  = box[i].options[selectedItem].text;
    		document.comboBox.sampTextarea.value=selectedItemText+"\n";
    	}
    
    }
    This function was to write the items in List 2 into the textarea, but it doesn't work. Can anybody see what I'm doing wrong with this?
    (please help, I'm running out of time!)


  •  

    Posting Permissions

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