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 10 of 10

Thread: beg for help

  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts

    beg for help

    Hi

    Please see my attachment

    i want to click the list at the left, which will then move the value of the option to the textarea on the right, i have tried to do it, but failed, i really hope somebody can help me out, as i need it very badly. Thanks a lot
    Attached Files Attached Files
    flying dagger

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kentucky
    Posts
    133
    Thanks
    0
    Thanked 1 Time in 1 Post
    You want to move the selected item over to the textarea, meaning you want to remove the item from the list on the left?

    I assumed that's what you want, so I took the liberty of changing your code, and pasting it here:

    Code:
    <html>
    <head>
    <title>Move List</title>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function MoveOption(objSourceElement, objTargetElement)
         {
    	var aryTempSourceOptions = new Array();
    	var aryTempTargetOptions = new Array();
    	var x = 0;
       
    	//looping through source element to find selected options
    	for (var i = 0; i < objSourceElement.length; i++) {
    		if (objSourceElement.options[i].selected) {
    			//need to move this option to target element
    			objTargetElement.innerHTML += objSourceElement.options[i].text;
    		}
        else {
         //storing options that stay to recreate select element
         var objTempValues = new Object();
         objTempValues.text = objSourceElement.options[i].text;
         objTempValues.value = objSourceElement.options[i].value;
         aryTempSourceOptions[x] = objTempValues;
         x++;
        }
       }
    
       //resetting length of source
       objSourceElement.length = aryTempSourceOptions.length;
       //looping through temp array to recreate source select element
       for (var i = 0; i < aryTempSourceOptions.length; i++) {
        objSourceElement.options[i].text = aryTempSourceOptions[i].text;
        objSourceElement.options[i].value = aryTempSourceOptions[i].value;
        objSourceElement.options[i].selected = false;
       }
         }
    
         function sortByText(a, b)
         {
       if (a.text < b.text) {return -1}
       if (a.text > b.text) {return 1}
       return 0;
         }
    
         function selectAll(objTargetElement)
         {
       for (var i = 0; i < objTargetElement.length; i++) {
        objTargetElement.options[i].selected = true;
       }
       return false;
      }
      //-->
     </SCRIPT>
        </head></PRE><PRE><body>
     <p><font face="Arial,Helvetica,sans-serif"><b>Demo for moving an Item from one list box to another, with a single click and passing one of the lists as all selected</b></font></p>
     <p><font face="Arial,Helvetica,sans-serif">Select Options to enable or disable</font></p>
     <form action="twoListsSorted.html" name="MoveList">
         <table>
      <tr>
          <td align="center"><font face="Arial,Helvetica,sans-serif" size="2"><b>Enabled</b></font></td>
          <td><p> </p></td>
          <td align="center"><font face="Arial,Helvetica,sans-serif" size="2"><b>Disabled</b></font></td>
      </tr>
      <tr>
          <td align="center" colspan=3><font face="Arial,Helvetica,sans-serif" size="2"><i>Click item to move it to the other list</i></font></td>
      </tr>
      <tr>
          <td>
       <select name="cboEnabled" size="5" multiple style="width: 100px;" onChange="MoveOption(this, document.forms[0].txtDisabled)">
           <option value="Option 1">Option 1</option>
           <option value="Option 2">Option 2</option>
           <option value="Option 3">Option 3</option>
           <option value="Option 4">Option 4</option>
           <option value="Option 5">Option 5</option>
           <option value="Option 6">Option 6</option>
       </select>
          </td>
          <td><p> </p></td>
          <td>
       <textarea name="txtDisabled" cols="20" rows="5" multiple style="width: 100px;" onChange="MoveOption()">
       </textarea>
          </td>
      </tr>
      <tr>
          <td align="right" colspan=3><INPUT TYPE="submit" onClick="selectAll(this.form.cboDisabled)"></td>
      </tr>
         </table>
     </form>
         <table>
      <tr>
          <td align="center" colspan=3>Disabled on the last pass:<br></td>
      </tr>
         </table>
      <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
       <!--
       var theDisplay = "\n";
       var queryString = location.search.substring(1);
       var nameValuePairs = queryString.split("&");
       for (var i = 0; i < nameValuePairs.length; i++) {
        var equalPosition = nameValuePairs[i].indexOf('=');
        if (equalPosition == -1)
         continue;
        var paramName = nameValuePairs[i].substring(0,equalPosition);
        var paramValue = nameValuePairs[i].substring(equalPosition+1);
        theDisplay+=(paramName+"="+paramValue+"<br>");
       }
       document.write(theDisplay);
       //-->
      </SCRIPT>
        </body>
    </html>
    Last edited by smeagol; 08-09-2006 at 06:20 PM.

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    thanks it is what i want, but how to make it new line in textarea every time i click the left and point the cursor at the new line?
    Last edited by xiaodao; 08-10-2006 at 01:55 PM.
    flying dagger

  • #4
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    please help, please...
    flying dagger

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    beg for help

    how to make it new line in textarea every time i click the left and point the cursor at the new line?


    thanks
    flying dagger

  • #6
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    up, please help,thanks
    flying dagger

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kentucky
    Posts
    133
    Thanks
    0
    Thanked 1 Time in 1 Post
    Sorry, I was out of town. Went to see the Amish in Holmes County Ohio.

    Here's the fixed code:

    Code:
    <html>
    <head>
    <title>Move List</title>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function MoveOption(objSourceElement, objTargetElement)
         {
    	var aryTempSourceOptions = new Array();
    	var aryTempTargetOptions = new Array();
    	var x = 0;
       
    	//looping through source element to find selected options
    	for (var i = 0; i < objSourceElement.length; i++) {
    		if (objSourceElement.options[i].selected) {
    			//need to move this option to target element
    			objTargetElement.innerHTML = objTargetElement.innerHTML + "\n" + objSourceElement.options[i].text;
    		}
        else {
         //storing options that stay to recreate select element
         var objTempValues = new Object();
         objTempValues.text = objSourceElement.options[i].text;
         objTempValues.value = objSourceElement.options[i].value;
         aryTempSourceOptions[x] = objTempValues;
         x++;
        }
       }
    
       //resetting length of source
       objSourceElement.length = aryTempSourceOptions.length;
       //looping through temp array to recreate source select element
       for (var i = 0; i < aryTempSourceOptions.length; i++) {
        objSourceElement.options[i].text = aryTempSourceOptions[i].text;
        objSourceElement.options[i].value = aryTempSourceOptions[i].value;
        objSourceElement.options[i].selected = false;
       }
         }
    
         function sortByText(a, b)
         {
       if (a.text < b.text) {return -1}
       if (a.text > b.text) {return 1}
       return 0;
         }
    
         function selectAll(objTargetElement)
         {
       for (var i = 0; i < objTargetElement.length; i++) {
        objTargetElement.options[i].selected = true;
       }
       return false;
      }
      //-->
     </SCRIPT>
        </head></PRE><PRE><body>
     <p><font face="Arial,Helvetica,sans-serif"><b>Demo for moving an Item from one list box to another, with a single click and passing one of the lists as all selected</b></font></p>
     <p><font face="Arial,Helvetica,sans-serif">Select Options to enable or disable</font></p>
     <form action="twoListsSorted.html" name="MoveList">
         <table>
      <tr>
          <td align="center"><font face="Arial,Helvetica,sans-serif" size="2"><b>Enabled</b></font></td>
          <td><p> </p></td>
          <td align="center"><font face="Arial,Helvetica,sans-serif" size="2"><b>Disabled</b></font></td>
      </tr>
      <tr>
          <td align="center" colspan=3><font face="Arial,Helvetica,sans-serif" size="2"><i>Click item to move it to the other list</i></font></td>
      </tr>
      <tr>
          <td>
       <select name="cboEnabled" size="5" multiple style="width: 100px;" onChange="MoveOption(this, document.forms[0].txtDisabled)">
           <option value="Option 1">Option 1</option>
           <option value="Option 2">Option 2</option>
           <option value="Option 3">Option 3</option>
           <option value="Option 4">Option 4</option>
           <option value="Option 5">Option 5</option>
           <option value="Option 6">Option 6</option>
       </select>
          </td>
          <td><p> </p></td>
          <td>
       <textarea name="txtDisabled" cols="20" rows="5" multiple style="width: 100px;" onChange="MoveOption()">
       </textarea>
          </td>
      </tr>
      <tr>
          <td align="right" colspan=3><INPUT TYPE="submit" onClick="selectAll(this.form.cboDisabled)"></td>
      </tr>
         </table>
     </form>
         <table>
      <tr>
          <td align="center" colspan=3>Disabled on the last pass:<br></td>
      </tr>
         </table>
      <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
       <!--
       var theDisplay = "\n";
       var queryString = location.search.substring(1);
       var nameValuePairs = queryString.split("&");
       for (var i = 0; i < nameValuePairs.length; i++) {
        var equalPosition = nameValuePairs[i].indexOf('=');
        if (equalPosition == -1)
         continue;
        var paramName = nameValuePairs[i].substring(0,equalPosition);
        var paramValue = nameValuePairs[i].substring(equalPosition+1);
        theDisplay+=(paramName+"="+paramValue+"<br>");
       }
       document.write(theDisplay);
       //-->
      </SCRIPT>
        </body>
    </html>

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Would not be easier to use two multiple list boxes and transfere an option from one to another with 2 buttons >> << using appendChild() DOM method? xiaodao, do you need those options to be sorted automatically after "translation", or not?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kentucky
    Posts
    133
    Thanks
    0
    Thanked 1 Time in 1 Post
    I wondered the same thing. I just did what he asked for by altering the script he already had. Apparently this script is pretty important to him (whether it makes sense or not).

  • #10
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    big thanks again, in fact i am using this script for a php application, the fact is that the user is lazy to type some lists which are stored in database, the textarea field is extremely important as user still need to input other information beside getting information from the option lists.
    flying dagger


  •  

    Posting Permissions

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