0

This isn't working:

function checkIt(String rep) {
         if (counter[$(rep).val()] == undefined) {
         count++;
         result = Math.round((count * 100 )/howMany);
         $('.percent').text(result);
         $('#perc_in').animate({'width': result+'%'}, 500);
         counter[$(this).val()] = 1;
         $('#counter').text(result);
         }
}

Like, at all... <_< I mean I think I am doing the function wrong.

Then inside the case statement I have this:

checkIt($(this).val());
0

1 Answer 1

3

Javascript is weak typed, so what in the world is this?

function checkIt(String rep) {

Just change it to

function checkIt(rep) {

It's also a bit odd that you are try to create a new jQuery object from the value of another form element. And this line:

if (counter[$(rep).val()] == undefined) {

This may be a little dangerous if you're just checking for the non-existence of an array element, since $(rep).val() could also be undefined depending on the situation.

Sign up to request clarification or add additional context in comments.

9 Comments

Also, it is unclear where count is defined, and what it is used for (if at all).
@karim Well, let's assume that all variables are declared. If not we could just as easily say that jQuery isn't properly load ;). As for uses erm... some sort of global count on how many times this function has been called?
@Yi Jiang - good point. Would be good to know, as it looks downright confusing :) I voted you up btw, that wasn't a 'gripe' but an innocuous (and I hoped useful) comment :)
OK that seems to work for only two of cases.... and I get undefnied when i do $(rep).val()...
@Dan Two possible reasons: 1. rep isn't a valid selector, so jQuery's returning undefined. 2. The element selected by $(rep) doesn't have a value attribute. Not that I didn't warn you on that in the answer...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.