1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice

Some javascript help - missing { before function body

Discussion in 'HTML & JavaScript' started by Scorpion Ghost, Apr 30, 2020.

  1. Scorpion Ghost

    Scorpion Ghost Jr. VIP Jr. VIP

    Joined:
    Mar 22, 2013
    Messages:
    3,273
    Likes Received:
    1,512
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    So I have some javascript that I use and it works on older version of Firefox, but on the latest version it will not work. I tried it in console, and I get this error:

    SyntaxError: missing { before function body

    This is the code:

    Code:
    var elems= document.querySelectorAll('[name^="Some Text"]');
    function doSetTimeout(i) {   setTimeout(function() 50); }
    for (var i = 0, len = elems.length; i < len; i++){ elems[i].value="3"; }
    doSetTimeout(i);
    What's the problem?
     
  2. Larry Igna

    Larry Igna Regular Member

    Joined:
    Nov 25, 2016
    Messages:
    324
    Likes Received:
    313
    Gender:
    Male
    Code:
    var elems= document.querySelectorAll('[name^="Some Text"]');
    function doSetTimeout(i) {
     setTimeout(function(){
     
    for (var i = 0, len = elems.length; i < len; i++){ elems[i].value="3"; }
     
     }, 50);
     }
    doSetTimeout(i);
    I think this is what you want
     
    • Thanks Thanks x 1
  3. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    6,371
    Likes Received:
    6,542
    Gender:
    Male
    Occupation:
    Programmer
    Location:
    Pale Blue Dot
    Code:
    var elems = document.querySelectorAll('[name^="Some Text"]');
    
    function doSetTimeout(i) {
        setTimeout(function(){}, 50);
    }
    for (var i = 0, len = elems.length; i < len; i++) {
        elems[i].value = "3";
    }
    doSetTimeout(i);
    It was missing the parenthesis and the comma in your setTimeout call.

    Btw the code does look nonsense :p

    that anonymous function doesn't do anything lol.
     
    • Thanks Thanks x 1
  4. Scorpion Ghost

    Scorpion Ghost Jr. VIP Jr. VIP

    Joined:
    Mar 22, 2013
    Messages:
    3,273
    Likes Received:
    1,512
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    Well all right, they both seem to work. Thank you booooooys :)

    Here's a nice song to thank you for the help :)