www.webdeveloper.com
Results 1 to 6 of 6

Thread: Syntax Error

  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Syntax Error

    I am having trouble figuring out what is wrong with the following line in my .js file. Can anyone help me? I can also post all the code if needed. Thanks!

    for (var i=0; i<myforms.length; i++) {

  2. #2
    Join Date
    Mar 2012
    Posts
    41
    i believe the for loop statement is wrong.

    for(var init;condition;var increment)

    what are you trying to there?

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    i<myforms.length;

    is it written the same way in your script?

  4. #4
    Join Date
    Apr 2012
    Posts
    3
    It is for a form to add spam bot protection. Here is all the code. The line that is giving me the error is line 5 (in red).

    // Set up
    addEvent(window, "load", setUpHumanTest, false);
    function setUpHumanTest() {
    var myforms = document.getElementsByTagName("form") ;
    for (var i=0; i<myforms.length; i++) {
    addEvent(myforms[i], "focus", markAsHuman, false);
    addEvent(myforms[i], "click", markAsHuman, false);
    }
    }

    // Identify a human
    function markAsHuman() {
    document.getElementById("imahuman").value = "1";
    }

    // Generic cross-browser code for attaching events to elements
    // You should really have this in a separate common JS file
    var addEvent;
    if (document.addEventListener) {
    addEvent = function(element, type, handler) {
    element.addEventListener(type, handler, null);
    if (element.href) element.href="javascript:void('');" ;
    }
    }
    else if (document.attachEvent) {
    addEvent = function(element, type, handler) {
    element.attachEvent("on" + type, handler);
    if (element.href) element.href="javascript:void('');" ;
    }
    }
    else {
    addEvent = new Function; // not supported
    }

  5. #5
    Join Date
    Nov 2010
    Posts
    1,102
    it got garbled in whatever you copied it from. &lt; is the character entity for < so really that line should be
    Code:
    for (var i=0; i<myforms.length; i++) {
    which is a fairly standard way to initialize a loop

  6. #6
    Join Date
    Apr 2012
    Posts
    3
    Thank you! That solved the problem.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles