Click to See Complete Forum and Search --> : about select adding and removing values


sampathreddyv2000
February 2nd, 2005, 01:48 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language='javascript'>
function addIndice()
{
var value = document.result1.indices.options.value;
result1.index.value = value;
var sel =document.result1.selectedind;
var l = sel.length;
sel.options[l] = new Option( value ,value);
}
function rmvIndice()
{
var x=document.getElementById("selectedind");
x.remove(x.selectedIndex);
}
</script>
</HEAD>

<BODY>
<form name="result1">
<table>
<tr>

<td>
<select name="indices" style="width:180" size="6" id="select">
<option value='one'> 1 </option>
<option value='two'> 2 </option>
<option value='three'> 3</option>
<option value='four'> 4/option>
<option value='five'> 5</option>
</select>
</td>
<td>
<select name="selectedind" style="width:180" size="6" multiple id="select">
<input type="hidden" name="index" value="" />
</select>
</td>
</tr>
<tr>
<td align="center">
<input type="button" name="add" value=" add " onClick="addIndice()" id="button"/>
</td>
<td align="center">
<input type="button" name="add" value=" remove " onclick="rmvIndice()" id="button"/>
</td>
</tr>
<table>
</form>
</body>
</html>


</BODY>
</HTML>


this code have two select boxes.one with values and second one with empty .
there is add buton below the first select box and remove button below the second one.if user select a value and click on add then the value is added to the second box.what i want is
example<option value='one'>1</option>

when we click add i want add 1 to second select box instead adding 'one'.

how can do this.
regards,

Vanny
February 15th, 2005, 07:11 PM
Hi There,

Try making a couple changes to your script


change value var as I dont think what you had is supported in all browsers

var value = document.result1.indices.options[document.result1.indices.selectedIndex].value;


Add below to get the text between <OPTION></OPTION>

var txt = document.result1.indices.options[document.result1.indices.selectedIndex].innerText;


Update adding to new select script to below.

new Option( txt ,value);