Unify code that works with selectmenu
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I have span and select in my view
Here is code of it
$(function()
var selectSpeed = $('#speed'),
selectTest = $('#test');
selectSpeed.selectmenu();
selectTest.selectmenu();
$("#speed-button").on("mousedown", function()
selectSpeed.selectmenu("open");
);
$('#speed-button').on("click", function()
selectSpeed.selectmenu("open");
);
$(document).on("mouseup", "#speed-menu .ui-menu-item-wrapper", function()
selectSpeed.val($(this).text().substr(0, 1)).change();
selectSpeed.selectmenu("close");
selectSpeed.selectmenu("refresh");
);
$("#test-button").on("mousedown", function()
selectTest.selectmenu("open");
);
$('#test-button').on("click", function()
selectTest.selectmenu("open");
);
$(document).on("mouseup", "#test-menu .ui-menu-item-wrapper", function()
selectTest.val($(this).text().substr(0, 1)).change();
selectTest.selectmenu("close");
selectTest.selectmenu("refresh");
);
);
fieldset
border: 0;
label
display: block;
margin: 30px 0 0 0;
.overflow
height: 200px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="demo">
<form action="#">
<fieldset>
<select name="speed" id="speed">
<option selected="selected" value="1">1 vuxen</option>
<option value="2">2 vuxna</option>
<option value="3">3 vuxna</option>
<option value="4">4 vuxna</option>
<option value="5">5 vuxna</option>
<option value="6">6 vuxna</option>
<option value="7">7 vuxna</option>
<option value="8">8 vuxna</option>
<option value="9">9 vuxna</option>
</select>
<select name="test" id="test">
<option selected="selected" value="1">1 test</option>
<option value="2">2 test</option>
<option value="3">3 test</option>
<option value="4">4 test</option>
<option value="5">5 test</option>
<option value="6">6 test</option>
<option value="7">7 test</option>
<option value="8">8 test</option>
<option value="9">9 test</option>
</select>
</fieldset>
</form>
</div>
For example I click span holding the mouse and then I move it to 2 vuxna and release it. And I would like to get 2 vuxna.
And same functionality for second select
But If I will have 3 selects, I need to define 3 variable and 3 $(document).on(
.
That's not great. I wonder if I have any ways to unify this code?
javascript jquery html jquery-ui
add a comment |Â
up vote
0
down vote
favorite
I have span and select in my view
Here is code of it
$(function()
var selectSpeed = $('#speed'),
selectTest = $('#test');
selectSpeed.selectmenu();
selectTest.selectmenu();
$("#speed-button").on("mousedown", function()
selectSpeed.selectmenu("open");
);
$('#speed-button').on("click", function()
selectSpeed.selectmenu("open");
);
$(document).on("mouseup", "#speed-menu .ui-menu-item-wrapper", function()
selectSpeed.val($(this).text().substr(0, 1)).change();
selectSpeed.selectmenu("close");
selectSpeed.selectmenu("refresh");
);
$("#test-button").on("mousedown", function()
selectTest.selectmenu("open");
);
$('#test-button').on("click", function()
selectTest.selectmenu("open");
);
$(document).on("mouseup", "#test-menu .ui-menu-item-wrapper", function()
selectTest.val($(this).text().substr(0, 1)).change();
selectTest.selectmenu("close");
selectTest.selectmenu("refresh");
);
);
fieldset
border: 0;
label
display: block;
margin: 30px 0 0 0;
.overflow
height: 200px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="demo">
<form action="#">
<fieldset>
<select name="speed" id="speed">
<option selected="selected" value="1">1 vuxen</option>
<option value="2">2 vuxna</option>
<option value="3">3 vuxna</option>
<option value="4">4 vuxna</option>
<option value="5">5 vuxna</option>
<option value="6">6 vuxna</option>
<option value="7">7 vuxna</option>
<option value="8">8 vuxna</option>
<option value="9">9 vuxna</option>
</select>
<select name="test" id="test">
<option selected="selected" value="1">1 test</option>
<option value="2">2 test</option>
<option value="3">3 test</option>
<option value="4">4 test</option>
<option value="5">5 test</option>
<option value="6">6 test</option>
<option value="7">7 test</option>
<option value="8">8 test</option>
<option value="9">9 test</option>
</select>
</fieldset>
</form>
</div>
For example I click span holding the mouse and then I move it to 2 vuxna and release it. And I would like to get 2 vuxna.
And same functionality for second select
But If I will have 3 selects, I need to define 3 variable and 3 $(document).on(
.
That's not great. I wonder if I have any ways to unify this code?
javascript jquery html jquery-ui
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have span and select in my view
Here is code of it
$(function()
var selectSpeed = $('#speed'),
selectTest = $('#test');
selectSpeed.selectmenu();
selectTest.selectmenu();
$("#speed-button").on("mousedown", function()
selectSpeed.selectmenu("open");
);
$('#speed-button').on("click", function()
selectSpeed.selectmenu("open");
);
$(document).on("mouseup", "#speed-menu .ui-menu-item-wrapper", function()
selectSpeed.val($(this).text().substr(0, 1)).change();
selectSpeed.selectmenu("close");
selectSpeed.selectmenu("refresh");
);
$("#test-button").on("mousedown", function()
selectTest.selectmenu("open");
);
$('#test-button').on("click", function()
selectTest.selectmenu("open");
);
$(document).on("mouseup", "#test-menu .ui-menu-item-wrapper", function()
selectTest.val($(this).text().substr(0, 1)).change();
selectTest.selectmenu("close");
selectTest.selectmenu("refresh");
);
);
fieldset
border: 0;
label
display: block;
margin: 30px 0 0 0;
.overflow
height: 200px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="demo">
<form action="#">
<fieldset>
<select name="speed" id="speed">
<option selected="selected" value="1">1 vuxen</option>
<option value="2">2 vuxna</option>
<option value="3">3 vuxna</option>
<option value="4">4 vuxna</option>
<option value="5">5 vuxna</option>
<option value="6">6 vuxna</option>
<option value="7">7 vuxna</option>
<option value="8">8 vuxna</option>
<option value="9">9 vuxna</option>
</select>
<select name="test" id="test">
<option selected="selected" value="1">1 test</option>
<option value="2">2 test</option>
<option value="3">3 test</option>
<option value="4">4 test</option>
<option value="5">5 test</option>
<option value="6">6 test</option>
<option value="7">7 test</option>
<option value="8">8 test</option>
<option value="9">9 test</option>
</select>
</fieldset>
</form>
</div>
For example I click span holding the mouse and then I move it to 2 vuxna and release it. And I would like to get 2 vuxna.
And same functionality for second select
But If I will have 3 selects, I need to define 3 variable and 3 $(document).on(
.
That's not great. I wonder if I have any ways to unify this code?
javascript jquery html jquery-ui
I have span and select in my view
Here is code of it
$(function()
var selectSpeed = $('#speed'),
selectTest = $('#test');
selectSpeed.selectmenu();
selectTest.selectmenu();
$("#speed-button").on("mousedown", function()
selectSpeed.selectmenu("open");
);
$('#speed-button').on("click", function()
selectSpeed.selectmenu("open");
);
$(document).on("mouseup", "#speed-menu .ui-menu-item-wrapper", function()
selectSpeed.val($(this).text().substr(0, 1)).change();
selectSpeed.selectmenu("close");
selectSpeed.selectmenu("refresh");
);
$("#test-button").on("mousedown", function()
selectTest.selectmenu("open");
);
$('#test-button').on("click", function()
selectTest.selectmenu("open");
);
$(document).on("mouseup", "#test-menu .ui-menu-item-wrapper", function()
selectTest.val($(this).text().substr(0, 1)).change();
selectTest.selectmenu("close");
selectTest.selectmenu("refresh");
);
);
fieldset
border: 0;
label
display: block;
margin: 30px 0 0 0;
.overflow
height: 200px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="demo">
<form action="#">
<fieldset>
<select name="speed" id="speed">
<option selected="selected" value="1">1 vuxen</option>
<option value="2">2 vuxna</option>
<option value="3">3 vuxna</option>
<option value="4">4 vuxna</option>
<option value="5">5 vuxna</option>
<option value="6">6 vuxna</option>
<option value="7">7 vuxna</option>
<option value="8">8 vuxna</option>
<option value="9">9 vuxna</option>
</select>
<select name="test" id="test">
<option selected="selected" value="1">1 test</option>
<option value="2">2 test</option>
<option value="3">3 test</option>
<option value="4">4 test</option>
<option value="5">5 test</option>
<option value="6">6 test</option>
<option value="7">7 test</option>
<option value="8">8 test</option>
<option value="9">9 test</option>
</select>
</fieldset>
</form>
</div>
For example I click span holding the mouse and then I move it to 2 vuxna and release it. And I would like to get 2 vuxna.
And same functionality for second select
But If I will have 3 selects, I need to define 3 variable and 3 $(document).on(
.
That's not great. I wonder if I have any ways to unify this code?
$(function()
var selectSpeed = $('#speed'),
selectTest = $('#test');
selectSpeed.selectmenu();
selectTest.selectmenu();
$("#speed-button").on("mousedown", function()
selectSpeed.selectmenu("open");
);
$('#speed-button').on("click", function()
selectSpeed.selectmenu("open");
);
$(document).on("mouseup", "#speed-menu .ui-menu-item-wrapper", function()
selectSpeed.val($(this).text().substr(0, 1)).change();
selectSpeed.selectmenu("close");
selectSpeed.selectmenu("refresh");
);
$("#test-button").on("mousedown", function()
selectTest.selectmenu("open");
);
$('#test-button').on("click", function()
selectTest.selectmenu("open");
);
$(document).on("mouseup", "#test-menu .ui-menu-item-wrapper", function()
selectTest.val($(this).text().substr(0, 1)).change();
selectTest.selectmenu("close");
selectTest.selectmenu("refresh");
);
);
fieldset
border: 0;
label
display: block;
margin: 30px 0 0 0;
.overflow
height: 200px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="demo">
<form action="#">
<fieldset>
<select name="speed" id="speed">
<option selected="selected" value="1">1 vuxen</option>
<option value="2">2 vuxna</option>
<option value="3">3 vuxna</option>
<option value="4">4 vuxna</option>
<option value="5">5 vuxna</option>
<option value="6">6 vuxna</option>
<option value="7">7 vuxna</option>
<option value="8">8 vuxna</option>
<option value="9">9 vuxna</option>
</select>
<select name="test" id="test">
<option selected="selected" value="1">1 test</option>
<option value="2">2 test</option>
<option value="3">3 test</option>
<option value="4">4 test</option>
<option value="5">5 test</option>
<option value="6">6 test</option>
<option value="7">7 test</option>
<option value="8">8 test</option>
<option value="9">9 test</option>
</select>
</fieldset>
</form>
</div>
$(function()
var selectSpeed = $('#speed'),
selectTest = $('#test');
selectSpeed.selectmenu();
selectTest.selectmenu();
$("#speed-button").on("mousedown", function()
selectSpeed.selectmenu("open");
);
$('#speed-button').on("click", function()
selectSpeed.selectmenu("open");
);
$(document).on("mouseup", "#speed-menu .ui-menu-item-wrapper", function()
selectSpeed.val($(this).text().substr(0, 1)).change();
selectSpeed.selectmenu("close");
selectSpeed.selectmenu("refresh");
);
$("#test-button").on("mousedown", function()
selectTest.selectmenu("open");
);
$('#test-button').on("click", function()
selectTest.selectmenu("open");
);
$(document).on("mouseup", "#test-menu .ui-menu-item-wrapper", function()
selectTest.val($(this).text().substr(0, 1)).change();
selectTest.selectmenu("close");
selectTest.selectmenu("refresh");
);
);
fieldset
border: 0;
label
display: block;
margin: 30px 0 0 0;
.overflow
height: 200px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="demo">
<form action="#">
<fieldset>
<select name="speed" id="speed">
<option selected="selected" value="1">1 vuxen</option>
<option value="2">2 vuxna</option>
<option value="3">3 vuxna</option>
<option value="4">4 vuxna</option>
<option value="5">5 vuxna</option>
<option value="6">6 vuxna</option>
<option value="7">7 vuxna</option>
<option value="8">8 vuxna</option>
<option value="9">9 vuxna</option>
</select>
<select name="test" id="test">
<option selected="selected" value="1">1 test</option>
<option value="2">2 test</option>
<option value="3">3 test</option>
<option value="4">4 test</option>
<option value="5">5 test</option>
<option value="6">6 test</option>
<option value="7">7 test</option>
<option value="8">8 test</option>
<option value="9">9 test</option>
</select>
</fieldset>
</form>
</div>
javascript jquery html jquery-ui
asked May 10 at 13:27
Balance
11
11
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194105%2funify-code-that-works-with-selectmenu%23new-answer', 'question_page');
);
Post as a guest
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
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
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