Panos
asked on
Problem with adding 1 to a number in a each function
Hello experts.
I have a problem with the following code:
var tmpcnt = 0;
alert(tmpcnt);
$.each(opt, function(index, value) {
alert(tmpcnt);
var cnt = parseInt(tmpcnt.value) + 1;
alert(cnt);
if (cnt == 3) {
var tmpcnt = 0;
} else {}
});
In the first alert i get 0 but the other alerts either have nothing ( the second) or i get a js error:tmpcnt is undefined
Any help?
I have a problem with the following code:
var tmpcnt = 0;
alert(tmpcnt);
$.each(opt, function(index, value) {
alert(tmpcnt);
var cnt = parseInt(tmpcnt.value) + 1;
alert(cnt);
if (cnt == 3) {
var tmpcnt = 0;
} else {}
});
In the first alert i get 0 but the other alerts either have nothing ( the second) or i get a js error:tmpcnt is undefined
Any help?
If tmpcnt is a variable then it has no value attribute (tmpcnt.value)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi thank you for your posts
leakim971 isn't work and doesn't work the same?
I get first alert 0 and the others NaN
leakim971 isn't work and doesn't work the same?
I get first alert 0 and the others NaN
Is there some HTML associated with this question? If so, could you please post the HTML as well as the JavaScript (jQuery)? Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The point of asking for the HTML was to be able to visualize the solution. It's not "needed" at one level, but it's useful to anyone who might come upon this question in the future. With the HTML + the jQuery, they might be able to copy / paste the code snippet and see it work.
ASKER
leakim971
the code is really working. I realized now the differences between the work and doesn't work. Sorry i made it difficult for you
Ray Paseur
To post an html code i have to create one. This code is part of a very large function.
The problem is not to show the function but to find the mistake in the code. That's why i made it as simple as possible for the experts deleting all unnecessary code.
the code is really working. I realized now the differences between the work and doesn't work. Sorry i made it difficult for you
Ray Paseur
To post an html code i have to create one. This code is part of a very large function.
The problem is not to show the function but to find the mistake in the code. That's why i made it as simple as possible for the experts deleting all unnecessary code.
ASKER
Thank you very much
regards
panos
regards
panos