Delete added items

I have a list in my form.

<span>
    <select size=5 id="submission_author_ids" name="submission[author_ids][]"  multiple onfocus="displayOptions();"> </select>
  </span>

I have a function that reads all the parameters in a list and then adds it to the div.

function displayOptions(){

var list = document.getElementById('submission_author_ids');
//$j('#spanSubmitters').remove();
for(var i = 0; i < list.options.length; ++i)
$j('#spanSubmitters').append(list.options[i].text);

 }

The problem is that every time the focus is displayed in the list, the parameters are added to the div. This can lead to duplication. I would like to remove all the added options in the div first and add the options again each time the list gets focus.

I tried the code below, but it does not work. Options are no longer displayed.

$j('#spanSubmitters').remove();

I would appreciate it if someone would help me with this.

Greetings

+3
source share
2 answers

Use empty () . remove()deletes the entire item. empty()just removes all child nodes inside it.

$j('#spanSubmitters').empty();
+4
source

Try the following:

$j('#spanSubmitters').children().remove();
+1
source

All Articles