-1

I am trying to set saveData when there is at least one field filled in:

    $(document).ready(function () {
        $(":input").each(function() {
            if($(this).val() != "") 
                window.setInterval(saveData, 5000);
        }
    });

There is a syntax error Expected ')' in this code.

What am I missing here?

4
  • 2
    You should try to use some IDE that highlights matching/missing parenthesis Commented Feb 8, 2012 at 9:36
  • Yeah. Visual Studio 2008 does not seem to have that. I have no option for the 2010 version now. Commented Feb 8, 2012 at 9:40
  • if you're doing just front-end programming you could try Eclipse IDE for JavaScript Web Developers Commented Feb 8, 2012 at 9:45
  • No it is both server and client side development. So no other option as of now. Existing website is in ASP.NET. So not possible. Thanks for letting me know of the possibility. Commented Feb 8, 2012 at 9:47

7 Answers 7

3

each() is a function, so you need to close its invocation parentheses. You are missing the trailing one.

$(document).ready(function () {
    $(":input").each(function() {
        if($(this).val() != "") 
            window.setInterval(saveData, 5000);
    }); // <-- You were missing the closing `)` here.
});
Sign up to request clarification or add additional context in comments.

1 Comment

Hey thanks your answer helped me. I will mark it in a few minutes. If you don't mind can you let me know how to modify the function to save data only when there is at least one field filled in. Currently it is doing the save when the form loads after the interval of 5 seconds. After that, it doesn't matter even if data is present in the form or not.
1

You are missing a ')' :

$(document).ready(function () {
    $(":input").each(function() {
        if($(this).val() != "") 
            window.setInterval(saveData, 5000);
    });
});

Comments

1
 $(document).ready(function () {
        $(":input").each(function() {
            if($(this).val() != "") 
                window.setInterval(saveData, 5000);
        });  <-- here
    });

Comments

1
$(document).ready(function () {
        $(":input").each(function() {
            if($(this).val() != "") 
                window.setInterval(saveData, 5000);
        });
    });

If I'm correct you forgot to close each() method..

Comments

1

You need to close your .each function:

$(document).ready(function () {
    $(":input").each(function() {
        if($(this).val() != "") 
            window.setInterval(saveData, 5000);
    });
});

Comments

1

In general, it is very helpful to use jslint to validate your javascript code

Comments

0

It must be window.setInterval("saveData()", 5000);

2 Comments

why? According some different guides, they use this syntax. Ok, he forgot the close braces, thoough I think he will run into next question.
They would be bad guides. The only reason I could think of to use that way is to preserve the this when calling an object's method and you must for some reason have terse code. Placing the function invocation in a string means that string needs to be eval()'d internally.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.