This topic is locked
[SOLVED]

 Dropdown items

2/13/2014 12:05:49 AM
PHPRunner General questions
M
macalister author

Hello.
I have two multiselect dropdowns, the first is a normal dropdown which loads data from a table and the second is a custom empty dropdown. When i select a item(s) of the first dropdown and press right arrow the items of the first dropdown sets in the second dropdown, and when i select the items of the second dropdown and i press supr key, the items are removed.
here is my code(OnLoad Event).


// add items from first dropdown to the second dropdown
var control = Runner.getControl(pageid, 'numControl'); // first dropdown
control.on('keydown', function(e){

if(e.keyCode == 39){
$('#box2').append(new Option(control.getValue(), control.getValue(), true, true));//add items from first dropdown
}

});
//remove items of the second dropdown
("#box2").keyup(function(e) {

if(e.keyCode == 46){
var $list = $("#box2"),

toRemove = $(),

selectedItems = $("#box2").val();



for (var i = selectedItems.length; i--<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=21984&image=1&table=forumtopics' class='bbc_emoticon' alt=';)' /> {

toRemove = toRemove.add($list.find('option[value="' + selectedItems[i] + '"]'));

}

toRemove.remove();
}

});


At this point all its ok, but im trying to do the same to remove items from the first dropdown when the right arrow key is pressed but its no possible.

Exists any way to do that?
Thanks.

Sergey Kornilov admin 2/13/2014

Removing items from dropdown lists is definitely possible and here is jQuery example:

http://stackoverflow.com/questions/1982449/jquery-to-remove-an-option-from-drop-down-list-given-options-text-value
I would also suggest checking multiselect plugin that is designed specifically for this purpose:

https://xlinesoft.com/marketplace/products_view.php?editid1=15

M
macalister author 2/13/2014



Removing items from dropdown lists is definitely possible and here is jQuery example:

http://stackoverflow.com/questions/1982449/jquery-to-remove-an-option-from-drop-down-list-given-options-text-value
I would also suggest checking multiselect plugin that is designed specifically for this purpose:

https://xlinesoft.com/marketplace/products_view.php?editid1=15


Thanks for response.
I made a mystake calling the id dropdown, I thought that the id was 'numControl' the same when i wish to get value from the dropdown (var control = Runner.getControl(pageid, 'numControl')).

I solved the problem getting the id of the dropdown inspecting the element in my case it was "value_numControl_1"
here is my code.



// add items from first dropdown to the second dropdown
var control = Runner.getControl(pageid, 'numControl'); // first dropdown

dropdownElement = $("#value_numControl_1"); //id of the first dropdown ********
function SortOptions(id) {//function sort items

var prePrepend = "#";

if (id.match("^#") == "#") prePrepend = "";

$(prePrepend + id).html($(prePrepend + id + " option").sort(

function (a, <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74027&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' /> { return a.text == b.text ? 0 : a.text < b.text ? -1 : 1 })

);

}
control.on('keydown', function(e){

if(e.keyCode == 39){
$('#box2').append(new Option(control.getValue(), control.getValue(), true, true));//add items from first dropdown

dropdownElement.find('option:selected').remove();//remove item of the first dropdown

SortOptions("#box2");// sort items of the second dropdown

}

});
//remove selected items of the second dropdown
("#box2").keyup(function(e) {

if(e.keyCode == 46){
var $list = $("#box2"),

toRemove = $(),

selectedItems = $("#box2").val();



for (var i = selectedItems.length; i--<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74027&image=2&table=forumreplies' class='bbc_emoticon' alt=';)' /> {

toRemove = toRemove.add($list.find('option[value="' + selectedItems[i] + '"]'));

}

toRemove.remove();
}

});


thank you very much for the support.