cesark
06-30-2004, 03:43 PM
Hi!
I have two ‘select’ boxes in order to chose one or more kinds of product quality. In the first ‘select’ I have several options to chose, and the second ‘select’ is empty. To make the selections, first I select one option from the first ‘select’ box, and then I click the link ‘add’ so that the text selected is showed in the second ‘select’ (with its value behind). And thus for every option I want to select.
But now, I want that If the user has selected several items from the first select object (with the control key pressed), I want that when the user presses the ‘add’ link, all the selections are passed to the second select object. And I want the same functionality when the user presses the link ‘delete’ to delete several items from the second select.
How can I do this?
The code page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script type="text/javascript">
function addArticle() {
for(var i=0; i<document.getElementById('selectedCert').length; i++) {
if(document.getElementById('selectedCert').options[i].value == document.getElementById('QualityCert').options[document.getElementById('QualityCert').selectedIndex].value) {
alert("Already exists");
return;
}
}
document.getElementById('selectedCert').options[document.getElementById('selectedCert').options.length]=new Option (document.getElementById('QualityCert').options[document.getElementById('QualityCert').selectedIndex].text, document.getElementById('QualityCert').options[document.getElementById('QualityCert').selectedIndex].value);
}
function removeArticle() {
var oChild = document.getElementById('selectedCert').children(document.getElementById('selectedCert').selectedInd ex);
document.getElementById('selectedCert').removeChild(oChild);
}
</script>
<body>
<table>
<form name="test">
<tr>
<td width="76">
<select name="QualityCert" size="4" multiple="multiple" style="height:140px;">
<option value="10">Quality 1</option>
<option value="20">Quality 2</option>
<option value="30">Quality 3</option>
<option value="40">Quality 4</option>
<option value="50">Quality 5</option>
<option value="60">Quality 6</option>
<option value="70">Quality 7</option>
<option value="80">Others</option>
</select>
</td>
<td width="76" align="center" valign="top"><p><a href="#" onClick="addArticle();">Add</a> <span>>></span></p>
<p><span><<</span> <a href="#" onClick="removeArticle();">Delete</a></p></td>
<td width="134" rowspan="2" align="left" valign="top"><select name="selectedCert" size="4" multiple="multiple" style="height:140px;width:75px;">
</select></td>
</tr>
</form>
</table>
</body>
</html>
Thank you,
Cesar
I have two ‘select’ boxes in order to chose one or more kinds of product quality. In the first ‘select’ I have several options to chose, and the second ‘select’ is empty. To make the selections, first I select one option from the first ‘select’ box, and then I click the link ‘add’ so that the text selected is showed in the second ‘select’ (with its value behind). And thus for every option I want to select.
But now, I want that If the user has selected several items from the first select object (with the control key pressed), I want that when the user presses the ‘add’ link, all the selections are passed to the second select object. And I want the same functionality when the user presses the link ‘delete’ to delete several items from the second select.
How can I do this?
The code page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script type="text/javascript">
function addArticle() {
for(var i=0; i<document.getElementById('selectedCert').length; i++) {
if(document.getElementById('selectedCert').options[i].value == document.getElementById('QualityCert').options[document.getElementById('QualityCert').selectedIndex].value) {
alert("Already exists");
return;
}
}
document.getElementById('selectedCert').options[document.getElementById('selectedCert').options.length]=new Option (document.getElementById('QualityCert').options[document.getElementById('QualityCert').selectedIndex].text, document.getElementById('QualityCert').options[document.getElementById('QualityCert').selectedIndex].value);
}
function removeArticle() {
var oChild = document.getElementById('selectedCert').children(document.getElementById('selectedCert').selectedInd ex);
document.getElementById('selectedCert').removeChild(oChild);
}
</script>
<body>
<table>
<form name="test">
<tr>
<td width="76">
<select name="QualityCert" size="4" multiple="multiple" style="height:140px;">
<option value="10">Quality 1</option>
<option value="20">Quality 2</option>
<option value="30">Quality 3</option>
<option value="40">Quality 4</option>
<option value="50">Quality 5</option>
<option value="60">Quality 6</option>
<option value="70">Quality 7</option>
<option value="80">Others</option>
</select>
</td>
<td width="76" align="center" valign="top"><p><a href="#" onClick="addArticle();">Add</a> <span>>></span></p>
<p><span><<</span> <a href="#" onClick="removeArticle();">Delete</a></p></td>
<td width="134" rowspan="2" align="left" valign="top"><select name="selectedCert" size="4" multiple="multiple" style="height:140px;width:75px;">
</select></td>
</tr>
</form>
</table>
</body>
</html>
Thank you,
Cesar