I want to turn the value I get from the id into a number and add one to it then pass the new value into the dosomething()
function to use. When I tried this and the value is one I get back 11 not 2.
$('.load_more').live("click",function() { // When user clicks var newcurrentpageTemp = $(this).attr("id") + 1;// Get id from the hyperlink alert(parseInt(newcurrentpageTemp)); dosomething(); });
How to convert a string to a number in JavaScript using the parseInt() function. Another way to convert a string into a number is to use the parseInt() function. This function takes in a string and an optional radix. A radix is a number between 2 and 36 which represents the base in a numeral system.
Method 1: Using number_format() Function. The number_format() function is used to convert string into a number. It returns the formatted number on success otherwise it gives E_WARNING on failure. echo number_format( $num , 2);
Assuming you are correct and your id is a proper number (without any other text), you should parse the id and then add one to it:
var currentPage = parseInt($(this).attr('id'), 10); ++currentPage; doSomething(currentPage);
Have you tried flip-flopping it a bit?
var newcurrentpageTemp = parseInt($(this).attr("id")); newcurrentpageTemp++; alert(newcurrentpageTemp));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With