HTML select change not working for jQuery function
I created a pagination for a table in a HTML page using jQuery. Following code is working.
$(document).ready(function(){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsShown = 10;
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
It shows 10 rows of the table per page and the pagination bar. Now I want to set the number of rows show per page dynamic. So I created a <select> with several <option> s like 10, 25, 50, 100
<select id="pagingCount" class="">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
and change the code as follows
var rowsShown = $('#pagingCount').val();
but it is not working. Always it shows 10 rows per page. How can I fix this?
jquery html
add a comment |
I created a pagination for a table in a HTML page using jQuery. Following code is working.
$(document).ready(function(){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsShown = 10;
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
It shows 10 rows of the table per page and the pagination bar. Now I want to set the number of rows show per page dynamic. So I created a <select> with several <option> s like 10, 25, 50, 100
<select id="pagingCount" class="">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
and change the code as follows
var rowsShown = $('#pagingCount').val();
but it is not working. Always it shows 10 rows per page. How can I fix this?
jquery html
why are you not using datatable using jquery i just write simple link flaviusmatis.github.io/simplePagination.js follow this
– Mohammad Malek
Nov 13 '18 at 5:18
I'm not allowed to use any external script other than jQuery.js
– David Johns
Nov 13 '18 at 5:28
try using$('#pagingCount option').val();
– Dark_thunder
Nov 13 '18 at 5:30
add a comment |
I created a pagination for a table in a HTML page using jQuery. Following code is working.
$(document).ready(function(){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsShown = 10;
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
It shows 10 rows of the table per page and the pagination bar. Now I want to set the number of rows show per page dynamic. So I created a <select> with several <option> s like 10, 25, 50, 100
<select id="pagingCount" class="">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
and change the code as follows
var rowsShown = $('#pagingCount').val();
but it is not working. Always it shows 10 rows per page. How can I fix this?
jquery html
I created a pagination for a table in a HTML page using jQuery. Following code is working.
$(document).ready(function(){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsShown = 10;
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
It shows 10 rows of the table per page and the pagination bar. Now I want to set the number of rows show per page dynamic. So I created a <select> with several <option> s like 10, 25, 50, 100
<select id="pagingCount" class="">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
and change the code as follows
var rowsShown = $('#pagingCount').val();
but it is not working. Always it shows 10 rows per page. How can I fix this?
jquery html
jquery html
asked Nov 13 '18 at 5:14
David JohnsDavid Johns
8011
8011
why are you not using datatable using jquery i just write simple link flaviusmatis.github.io/simplePagination.js follow this
– Mohammad Malek
Nov 13 '18 at 5:18
I'm not allowed to use any external script other than jQuery.js
– David Johns
Nov 13 '18 at 5:28
try using$('#pagingCount option').val();
– Dark_thunder
Nov 13 '18 at 5:30
add a comment |
why are you not using datatable using jquery i just write simple link flaviusmatis.github.io/simplePagination.js follow this
– Mohammad Malek
Nov 13 '18 at 5:18
I'm not allowed to use any external script other than jQuery.js
– David Johns
Nov 13 '18 at 5:28
try using$('#pagingCount option').val();
– Dark_thunder
Nov 13 '18 at 5:30
why are you not using datatable using jquery i just write simple link flaviusmatis.github.io/simplePagination.js follow this
– Mohammad Malek
Nov 13 '18 at 5:18
why are you not using datatable using jquery i just write simple link flaviusmatis.github.io/simplePagination.js follow this
– Mohammad Malek
Nov 13 '18 at 5:18
I'm not allowed to use any external script other than jQuery.js
– David Johns
Nov 13 '18 at 5:28
I'm not allowed to use any external script other than jQuery.js
– David Johns
Nov 13 '18 at 5:28
try using
$('#pagingCount option').val();– Dark_thunder
Nov 13 '18 at 5:30
try using
$('#pagingCount option').val();– Dark_thunder
Nov 13 '18 at 5:30
add a comment |
3 Answers
3
active
oldest
votes
You will have to change the value of rowsShown in your code block.
function showRows(rowsShown){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
}
$(document).ready(function(){
showRows(10);
});
$("#pagingCount").on("change", function(e){
showRows(e.target.value);
});
Hope this will work for you.
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
If you need to remove previous pages, you can simply use.remove()method of jquery.
– Lovlesh Pokra
Nov 13 '18 at 6:39
add a comment |
You have to try use :selected to get the current value.
var rowsShown = $('#pagingCount option:selected').val();
add a comment |
You can achieve selected value by using this code.
Its simple in JQuery to get selected value.
var rowsShown= $('#pagingCount').find(":selected").text();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53274235%2fhtml-select-change-not-working-for-jquery-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You will have to change the value of rowsShown in your code block.
function showRows(rowsShown){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
}
$(document).ready(function(){
showRows(10);
});
$("#pagingCount").on("change", function(e){
showRows(e.target.value);
});
Hope this will work for you.
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
If you need to remove previous pages, you can simply use.remove()method of jquery.
– Lovlesh Pokra
Nov 13 '18 at 6:39
add a comment |
You will have to change the value of rowsShown in your code block.
function showRows(rowsShown){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
}
$(document).ready(function(){
showRows(10);
});
$("#pagingCount").on("change", function(e){
showRows(e.target.value);
});
Hope this will work for you.
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
If you need to remove previous pages, you can simply use.remove()method of jquery.
– Lovlesh Pokra
Nov 13 '18 at 6:39
add a comment |
You will have to change the value of rowsShown in your code block.
function showRows(rowsShown){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
}
$(document).ready(function(){
showRows(10);
});
$("#pagingCount").on("change", function(e){
showRows(e.target.value);
});
Hope this will work for you.
You will have to change the value of rowsShown in your code block.
function showRows(rowsShown){
$('#transactionsTable').after('<ul id="nav" class="pagination"></ul>');
var rowsTotal = $('#transactionsTable tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<li class="page-item"><a class="page-link" href="#" rel="'+i+'">'+pageNum+'</a></li> ');
}
$('#transactionsTable tbody tr').hide();
$('#transactionsTable tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#transactionsTable tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
}
$(document).ready(function(){
showRows(10);
});
$("#pagingCount").on("change", function(e){
showRows(e.target.value);
});
Hope this will work for you.
answered Nov 13 '18 at 6:01
Lovlesh PokraLovlesh Pokra
1063
1063
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
If you need to remove previous pages, you can simply use.remove()method of jquery.
– Lovlesh Pokra
Nov 13 '18 at 6:39
add a comment |
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
If you need to remove previous pages, you can simply use.remove()method of jquery.
– Lovlesh Pokra
Nov 13 '18 at 6:39
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
When I tried to change the value from select, page will keep the previous pagination bar as well. Ex. At the start, there are 5 pages for 10 per page. After change it to 25 per page, it shows 2 pages with previous 5 pages so total 7 pages
– David Johns
Nov 13 '18 at 6:20
If you need to remove previous pages, you can simply use
.remove() method of jquery.– Lovlesh Pokra
Nov 13 '18 at 6:39
If you need to remove previous pages, you can simply use
.remove() method of jquery.– Lovlesh Pokra
Nov 13 '18 at 6:39
add a comment |
You have to try use :selected to get the current value.
var rowsShown = $('#pagingCount option:selected').val();
add a comment |
You have to try use :selected to get the current value.
var rowsShown = $('#pagingCount option:selected').val();
add a comment |
You have to try use :selected to get the current value.
var rowsShown = $('#pagingCount option:selected').val();
You have to try use :selected to get the current value.
var rowsShown = $('#pagingCount option:selected').val();
answered Nov 13 '18 at 5:40
juanObrachjuanObrach
79512
79512
add a comment |
add a comment |
You can achieve selected value by using this code.
Its simple in JQuery to get selected value.
var rowsShown= $('#pagingCount').find(":selected").text();
add a comment |
You can achieve selected value by using this code.
Its simple in JQuery to get selected value.
var rowsShown= $('#pagingCount').find(":selected").text();
add a comment |
You can achieve selected value by using this code.
Its simple in JQuery to get selected value.
var rowsShown= $('#pagingCount').find(":selected").text();
You can achieve selected value by using this code.
Its simple in JQuery to get selected value.
var rowsShown= $('#pagingCount').find(":selected").text();
answered Nov 13 '18 at 5:49
Muddasir23Muddasir23
1089
1089
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53274235%2fhtml-select-change-not-working-for-jquery-function%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
why are you not using datatable using jquery i just write simple link flaviusmatis.github.io/simplePagination.js follow this
– Mohammad Malek
Nov 13 '18 at 5:18
I'm not allowed to use any external script other than jQuery.js
– David Johns
Nov 13 '18 at 5:28
try using
$('#pagingCount option').val();– Dark_thunder
Nov 13 '18 at 5:30