I am using the select2 plugin. How to make the selected option after clicking on the SEND not fought?
up vote
0
down vote
favorite
I have such a problem .. in the localStorage of the Sahranet there is only one selected element and after append at it is duplicated
<form method='GET'>
<select class='select' multiple='multiple'>
<option value='a2'>aladin</option>
<option value='3s'>ark</option>
<option value='4a'>asdasdtaktak</option>
<option value='5f'>ametis</option>
</select>
<input type='submit' value='send'>
</form>
$(document).ready(function($){
$('.select').select2({});
$('.select').on('select2:select', function (e) {
var data = e.params.data;
testObject={
'id': data.id,
'text':data.text
}
localStorage.setItem("lastname", JSON.stringify(testObject) );
});
if(localStorage.getItem('lastname')){
var data= JSON.parse(localStorage.getItem('lastname'));
console.log(data.id );
var newOption = new Option(data.text, data.id, false, true);
$('.select').append(newOption).trigger('change');
}
});
php jquery jquery-select2
add a comment |
up vote
0
down vote
favorite
I have such a problem .. in the localStorage of the Sahranet there is only one selected element and after append at it is duplicated
<form method='GET'>
<select class='select' multiple='multiple'>
<option value='a2'>aladin</option>
<option value='3s'>ark</option>
<option value='4a'>asdasdtaktak</option>
<option value='5f'>ametis</option>
</select>
<input type='submit' value='send'>
</form>
$(document).ready(function($){
$('.select').select2({});
$('.select').on('select2:select', function (e) {
var data = e.params.data;
testObject={
'id': data.id,
'text':data.text
}
localStorage.setItem("lastname", JSON.stringify(testObject) );
});
if(localStorage.getItem('lastname')){
var data= JSON.parse(localStorage.getItem('lastname'));
console.log(data.id );
var newOption = new Option(data.text, data.id, false, true);
$('.select').append(newOption).trigger('change');
}
});
php jquery jquery-select2
Trynew Option(data.text, data.id, false, false);
to not select the option when appending: developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/…
– Niloct
Nov 10 at 17:44
in this case, I can not see the selected item
– Artak
Nov 10 at 17:59
I solved the problem like this..$('.select').val(data.id).trigger('change');.))).. but save to localStorage multiple items fail((
– Artak
Nov 10 at 18:10
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have such a problem .. in the localStorage of the Sahranet there is only one selected element and after append at it is duplicated
<form method='GET'>
<select class='select' multiple='multiple'>
<option value='a2'>aladin</option>
<option value='3s'>ark</option>
<option value='4a'>asdasdtaktak</option>
<option value='5f'>ametis</option>
</select>
<input type='submit' value='send'>
</form>
$(document).ready(function($){
$('.select').select2({});
$('.select').on('select2:select', function (e) {
var data = e.params.data;
testObject={
'id': data.id,
'text':data.text
}
localStorage.setItem("lastname", JSON.stringify(testObject) );
});
if(localStorage.getItem('lastname')){
var data= JSON.parse(localStorage.getItem('lastname'));
console.log(data.id );
var newOption = new Option(data.text, data.id, false, true);
$('.select').append(newOption).trigger('change');
}
});
php jquery jquery-select2
I have such a problem .. in the localStorage of the Sahranet there is only one selected element and after append at it is duplicated
<form method='GET'>
<select class='select' multiple='multiple'>
<option value='a2'>aladin</option>
<option value='3s'>ark</option>
<option value='4a'>asdasdtaktak</option>
<option value='5f'>ametis</option>
</select>
<input type='submit' value='send'>
</form>
$(document).ready(function($){
$('.select').select2({});
$('.select').on('select2:select', function (e) {
var data = e.params.data;
testObject={
'id': data.id,
'text':data.text
}
localStorage.setItem("lastname", JSON.stringify(testObject) );
});
if(localStorage.getItem('lastname')){
var data= JSON.parse(localStorage.getItem('lastname'));
console.log(data.id );
var newOption = new Option(data.text, data.id, false, true);
$('.select').append(newOption).trigger('change');
}
});
php jquery jquery-select2
php jquery jquery-select2
asked Nov 10 at 17:25
Artak
1
1
Trynew Option(data.text, data.id, false, false);
to not select the option when appending: developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/…
– Niloct
Nov 10 at 17:44
in this case, I can not see the selected item
– Artak
Nov 10 at 17:59
I solved the problem like this..$('.select').val(data.id).trigger('change');.))).. but save to localStorage multiple items fail((
– Artak
Nov 10 at 18:10
add a comment |
Trynew Option(data.text, data.id, false, false);
to not select the option when appending: developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/…
– Niloct
Nov 10 at 17:44
in this case, I can not see the selected item
– Artak
Nov 10 at 17:59
I solved the problem like this..$('.select').val(data.id).trigger('change');.))).. but save to localStorage multiple items fail((
– Artak
Nov 10 at 18:10
Try
new Option(data.text, data.id, false, false);
to not select the option when appending: developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/…– Niloct
Nov 10 at 17:44
Try
new Option(data.text, data.id, false, false);
to not select the option when appending: developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/…– Niloct
Nov 10 at 17:44
in this case, I can not see the selected item
– Artak
Nov 10 at 17:59
in this case, I can not see the selected item
– Artak
Nov 10 at 17:59
I solved the problem like this..$('.select').val(data.id).trigger('change');.))).. but save to localStorage multiple items fail((
– Artak
Nov 10 at 18:10
I solved the problem like this..$('.select').val(data.id).trigger('change');.))).. but save to localStorage multiple items fail((
– Artak
Nov 10 at 18:10
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241545%2fi-am-using-the-select2-plugin-how-to-make-the-selected-option-after-clicking-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try
new Option(data.text, data.id, false, false);
to not select the option when appending: developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/…– Niloct
Nov 10 at 17:44
in this case, I can not see the selected item
– Artak
Nov 10 at 17:59
I solved the problem like this..$('.select').val(data.id).trigger('change');.))).. but save to localStorage multiple items fail((
– Artak
Nov 10 at 18:10