Loading ...
Sorry, an error occurred while loading the content.

JSLint -- questions about some restrictions

Expand Messages
  • fashionablywired
    I m using JSLint to help clean up my Javascript code, but it has very high standards. I have one section in my program where I need to populate a listbox from
    Message 1 of 2 , Jul 10, 2009
    • 0 Attachment
      I'm using JSLint to help clean up my Javascript code, but it has very high standards. I have one section in my program where I need to populate a listbox from the contents of an array. I'm using the document.write statement -- I copied it from snippets on the web for this purpose.

      But JSLint believes this is a form of EVAL. I turned the option off to get through the checker, but I'm curious, how else can I do this?

      Also, it "advises" not to use HTML events. How else do you trigger a script on a listbox click?

      Open to suggestions.
    • Max
      You can try using addEventListener to your JS code to fire when click event is detected on the element (in your case listbox). Now, I do not claim to be an
      Message 2 of 2 , Jul 12, 2009
      • 0 Attachment
        You can try using addEventListener to your JS code to fire when click event is detected on the element (in your case listbox).

        Now, I do not claim to be an expert in this, but this works for me when I want to add an element to the page dynamically

        function testFunction(){
        this is where the code for the adding elements go
        }
        function addListeners(){
        var test=document.getElementById("testDiv");
        test.addEventListener("click",testFunction,false);
        }

        You can google addEventListener, there are a ton of posts dealing with this subject.

        Good Luck.

        Max.

        --- In JavaScript_Official@yahoogroups.com, "fashionablywired" <fashionablywired@...> wrote:
        >
        > I'm using JSLint to help clean up my Javascript code, but it has very high standards. I have one section in my program where I need to populate a listbox from the contents of an array. I'm using the document.write statement -- I copied it from snippets on the web for this purpose.
        >
        > But JSLint believes this is a form of EVAL. I turned the option off to get through the checker, but I'm curious, how else can I do this?
        >
        > Also, it "advises" not to use HTML events. How else do you trigger a script on a listbox click?
        >
        > Open to suggestions.
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.