...

View Full Version : strange behavior when removing option from select



frontline
07-10-2003, 12:04 PM
Hello
i have strange thing when im trying to remove option from options collection
when the right scroller of the selectbox is in the middle of the its scrll(or scroll path or what ever to call it)
then im trying to delete the top must visible option whit the foo(i) function you will see blank space that this option leaves
and when you press this blank space you will see duplication of the option that was under the option i removed.....
why?
here is the sample code:
just important note: this only happens when the select scroller is somewhere but not in it top default position
and the option you try to remove is the top must visible option.
otherwise it not gona work
--------------------------------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function foo(i){
document.all['Operation'].options[i]=null;
}
</script>
</HEAD>
<BODY>
<select size=5 name="Operation" style="width:400px" >
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
</select>
<br>
<input type="button" onclick="foo(document.all['Operation'].options.selectedIndex)">
</BODY>
</HTML>
--------------------------------------------------------------------------------------------------

Roelf
07-10-2003, 12:14 PM
try


function foo(i){
document.all['Operation'].remove(i)
}

frontline
07-10-2003, 12:20 PM
nop .. the same

Kor
07-10-2003, 03:30 PM
try

function foo(i){
document.all['Operation'].options.i=null;
}
and

onclick="foo('selectedIndex')">

That seems , at least, correct to me to use an argument...

PauletteB
07-10-2003, 03:33 PM
Maybe

<form>
<select size=5 name="Operation" style="width:400px">
<option value= "0">0</option>
<option value= "1">1</option>
<option value= "2">2</option>
......
</select>
</form>

Kor
07-10-2003, 03:46 PM
No, paullete, the function uses selectedIndex, not value but, who knows, maybe it a good ideea to use value somehow...

cheesebagpipe
07-11-2003, 12:15 AM
Wow...strange indeed. Haven't seen this one before. Seems to have something to do with the repaint of the altered select - which isn't being done properly - but, why...who knows? This seems to fix it (X-browser, too):


<html>
<head>
<title> New Document </title>
<script type="text/javascript">

function delSelOpt(oSelect) {
var idx = oSelect.selectedIndex;
oSelect.options[idx] = null;
oSelect.selectedIndex = 0;
oSelect.selectedIndex = idx;
}

</script>
</head>
<body>
<select size=5 name="Operation" style="width:400px" >
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
</select>
<br>
<input type="button" value="Delete Selected Option" onclick="delSelOpt(Operation)">
</body>
</html>

Jerking it around seems to wake it up. Maybe someone else knows a standard fix for this.

mordred
07-11-2003, 12:28 AM
Just to add to the confusion: I am not able to reproduce the buggy behaviour in IE5.5 on Win2k. No blank space left.
It's better to use a form tag around form elements though, and to access the form not by document.all.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum