...

View Full Version : beg for help



xiaodao
08-09-2006, 05:44 PM
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

smeagol
08-09-2006, 06:07 PM
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:



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

xiaodao
08-10-2006, 12:12 AM
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?

xiaodao
08-10-2006, 01:55 PM
please help, please...

xiaodao
08-11-2006, 03:25 PM
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

xiaodao
08-12-2006, 01:28 PM
up, please help,thanks

smeagol
08-12-2006, 06:03 PM
Sorry, I was out of town. Went to see the Amish in Holmes County Ohio.

Here's the fixed 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>

Kor
08-12-2006, 07:17 PM
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?

smeagol
08-12-2006, 10:04 PM
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).

xiaodao
08-13-2006, 02:01 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum