Javascript string undefined












4














I have a code like this:






<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>





I wanted to make it alert its own alphabet(value), but it doesn't work.



So for example, when I click A Button, the program should alert 'A'.



But it alerts 'undefined'.



I don't know what the problem is.



I want to make my code work properly.



How can I make it?










share|improve this question






















  • What do you think self.id is?
    – tkausl
    Nov 11 at 6:23










  • @tkausl self.id should be button's own alphabet. So for example, when I click C button, its id is C, and self.id is C. So, when isTOF function runs, v == C. But now it doesn't work like that.
    – Hoseong Jeon
    Nov 11 at 6:24










  • It doesn't work because self doesn't exist
    – tkausl
    Nov 11 at 6:25










  • @tkausl Oh, thank you so much. But why self doesn't exist?
    – Hoseong Jeon
    Nov 11 at 6:26






  • 1




    But it looks like this.id will work ...
    – moilejter
    Nov 11 at 6:30
















4














I have a code like this:






<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>





I wanted to make it alert its own alphabet(value), but it doesn't work.



So for example, when I click A Button, the program should alert 'A'.



But it alerts 'undefined'.



I don't know what the problem is.



I want to make my code work properly.



How can I make it?










share|improve this question






















  • What do you think self.id is?
    – tkausl
    Nov 11 at 6:23










  • @tkausl self.id should be button's own alphabet. So for example, when I click C button, its id is C, and self.id is C. So, when isTOF function runs, v == C. But now it doesn't work like that.
    – Hoseong Jeon
    Nov 11 at 6:24










  • It doesn't work because self doesn't exist
    – tkausl
    Nov 11 at 6:25










  • @tkausl Oh, thank you so much. But why self doesn't exist?
    – Hoseong Jeon
    Nov 11 at 6:26






  • 1




    But it looks like this.id will work ...
    – moilejter
    Nov 11 at 6:30














4












4








4


1





I have a code like this:






<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>





I wanted to make it alert its own alphabet(value), but it doesn't work.



So for example, when I click A Button, the program should alert 'A'.



But it alerts 'undefined'.



I don't know what the problem is.



I want to make my code work properly.



How can I make it?










share|improve this question













I have a code like this:






<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>





I wanted to make it alert its own alphabet(value), but it doesn't work.



So for example, when I click A Button, the program should alert 'A'.



But it alerts 'undefined'.



I don't know what the problem is.



I want to make my code work properly.



How can I make it?






<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>





<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>






javascript html






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 6:22









Hoseong Jeon

24112




24112












  • What do you think self.id is?
    – tkausl
    Nov 11 at 6:23










  • @tkausl self.id should be button's own alphabet. So for example, when I click C button, its id is C, and self.id is C. So, when isTOF function runs, v == C. But now it doesn't work like that.
    – Hoseong Jeon
    Nov 11 at 6:24










  • It doesn't work because self doesn't exist
    – tkausl
    Nov 11 at 6:25










  • @tkausl Oh, thank you so much. But why self doesn't exist?
    – Hoseong Jeon
    Nov 11 at 6:26






  • 1




    But it looks like this.id will work ...
    – moilejter
    Nov 11 at 6:30


















  • What do you think self.id is?
    – tkausl
    Nov 11 at 6:23










  • @tkausl self.id should be button's own alphabet. So for example, when I click C button, its id is C, and self.id is C. So, when isTOF function runs, v == C. But now it doesn't work like that.
    – Hoseong Jeon
    Nov 11 at 6:24










  • It doesn't work because self doesn't exist
    – tkausl
    Nov 11 at 6:25










  • @tkausl Oh, thank you so much. But why self doesn't exist?
    – Hoseong Jeon
    Nov 11 at 6:26






  • 1




    But it looks like this.id will work ...
    – moilejter
    Nov 11 at 6:30
















What do you think self.id is?
– tkausl
Nov 11 at 6:23




What do you think self.id is?
– tkausl
Nov 11 at 6:23












@tkausl self.id should be button's own alphabet. So for example, when I click C button, its id is C, and self.id is C. So, when isTOF function runs, v == C. But now it doesn't work like that.
– Hoseong Jeon
Nov 11 at 6:24




@tkausl self.id should be button's own alphabet. So for example, when I click C button, its id is C, and self.id is C. So, when isTOF function runs, v == C. But now it doesn't work like that.
– Hoseong Jeon
Nov 11 at 6:24












It doesn't work because self doesn't exist
– tkausl
Nov 11 at 6:25




It doesn't work because self doesn't exist
– tkausl
Nov 11 at 6:25












@tkausl Oh, thank you so much. But why self doesn't exist?
– Hoseong Jeon
Nov 11 at 6:26




@tkausl Oh, thank you so much. But why self doesn't exist?
– Hoseong Jeon
Nov 11 at 6:26




1




1




But it looks like this.id will work ...
– moilejter
Nov 11 at 6:30




But it looks like this.id will work ...
– moilejter
Nov 11 at 6:30












3 Answers
3






active

oldest

votes


















3














The problem you are having is caused by self not being defined. Instead, you should use the value that you already set, and pass in this to isTOF:






<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(this)");
document.body.appendChild(x);
}
}

function isTOF(v) {
alert(v.value);
}
</script>
</head>
<body>
</body>
</html>





This way, you are passing a reference to the element to isTOF in case you want to do anything with it or just for purely information purposes.



Hope this helps!






share|improve this answer























  • @HoseongJeon glad I could help!
    – Derek Pollard
    Nov 11 at 6:38



















2














The problem is:



x.setAttribute("onclick", "isTOF(self.id)");


There's no variable named self in scope at that point. Perhaps you meant to use this, which would work:






for (i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(this.id)");
document.body.appendChild(x);
}

function isTOF(v) {
alert(v);
}





But since you have a direct reference to the element already, rather than assign a string attribute in the HTML to be turned into a handler (which is basically eval in the form of an HTML attribute), it would be better to attach the listener properly using Javascript - which will make things easier, because then the id, if you set a variable to it beforehand, can simply be referenced again in the handler, rather than having to check this.id. In addition, you can often use dot notation rather than setAttribute, which is more concise and easier to read, so it's probably preferable in most cases:






for (let i = 0; i < 26; i++) {
const x = document.createElement("INPUT");
x.type = 'button';
const id = String.fromCharCode(i + 65);
x.value = id;
x.id = id;
x.onclick = () => isTOF(id);
document.body.appendChild(x);
}

function isTOF(v) {
console.log(v);
}








share|improve this answer





























    2














    I would use an event listener instead like so:






    function isTOF(e) {
    console.log("id:["+ this.id +"], value:["+ this.value +"]");
    }
    window.onload = function() {
    for(i = 0; i < 26; i++) {
    var x = document.createElement("INPUT");
    x.setAttribute("type", "button");
    x.setAttribute("value", String.fromCharCode(i + 65));
    x.setAttribute("id", String.fromCharCode(i + 65));
    x.addEventListener("click", isTOF, false);
    document.body.appendChild(x);
    }
    }








    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246363%2fjavascript-string-undefined%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      The problem you are having is caused by self not being defined. Instead, you should use the value that you already set, and pass in this to isTOF:






      <html>
      <head>
      <script language="javascript">
      window.onload = function() {
      for(i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this)");
      document.body.appendChild(x);
      }
      }

      function isTOF(v) {
      alert(v.value);
      }
      </script>
      </head>
      <body>
      </body>
      </html>





      This way, you are passing a reference to the element to isTOF in case you want to do anything with it or just for purely information purposes.



      Hope this helps!






      share|improve this answer























      • @HoseongJeon glad I could help!
        – Derek Pollard
        Nov 11 at 6:38
















      3














      The problem you are having is caused by self not being defined. Instead, you should use the value that you already set, and pass in this to isTOF:






      <html>
      <head>
      <script language="javascript">
      window.onload = function() {
      for(i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this)");
      document.body.appendChild(x);
      }
      }

      function isTOF(v) {
      alert(v.value);
      }
      </script>
      </head>
      <body>
      </body>
      </html>





      This way, you are passing a reference to the element to isTOF in case you want to do anything with it or just for purely information purposes.



      Hope this helps!






      share|improve this answer























      • @HoseongJeon glad I could help!
        – Derek Pollard
        Nov 11 at 6:38














      3












      3








      3






      The problem you are having is caused by self not being defined. Instead, you should use the value that you already set, and pass in this to isTOF:






      <html>
      <head>
      <script language="javascript">
      window.onload = function() {
      for(i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this)");
      document.body.appendChild(x);
      }
      }

      function isTOF(v) {
      alert(v.value);
      }
      </script>
      </head>
      <body>
      </body>
      </html>





      This way, you are passing a reference to the element to isTOF in case you want to do anything with it or just for purely information purposes.



      Hope this helps!






      share|improve this answer














      The problem you are having is caused by self not being defined. Instead, you should use the value that you already set, and pass in this to isTOF:






      <html>
      <head>
      <script language="javascript">
      window.onload = function() {
      for(i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this)");
      document.body.appendChild(x);
      }
      }

      function isTOF(v) {
      alert(v.value);
      }
      </script>
      </head>
      <body>
      </body>
      </html>





      This way, you are passing a reference to the element to isTOF in case you want to do anything with it or just for purely information purposes.



      Hope this helps!






      <html>
      <head>
      <script language="javascript">
      window.onload = function() {
      for(i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this)");
      document.body.appendChild(x);
      }
      }

      function isTOF(v) {
      alert(v.value);
      }
      </script>
      </head>
      <body>
      </body>
      </html>





      <html>
      <head>
      <script language="javascript">
      window.onload = function() {
      for(i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this)");
      document.body.appendChild(x);
      }
      }

      function isTOF(v) {
      alert(v.value);
      }
      </script>
      </head>
      <body>
      </body>
      </html>






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 11 at 6:32

























      answered Nov 11 at 6:27









      Derek Pollard

      3,81022239




      3,81022239












      • @HoseongJeon glad I could help!
        – Derek Pollard
        Nov 11 at 6:38


















      • @HoseongJeon glad I could help!
        – Derek Pollard
        Nov 11 at 6:38
















      @HoseongJeon glad I could help!
      – Derek Pollard
      Nov 11 at 6:38




      @HoseongJeon glad I could help!
      – Derek Pollard
      Nov 11 at 6:38













      2














      The problem is:



      x.setAttribute("onclick", "isTOF(self.id)");


      There's no variable named self in scope at that point. Perhaps you meant to use this, which would work:






      for (i = 0; i < 26; i++) {
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", String.fromCharCode(i + 65));
      x.setAttribute("id", String.fromCharCode(i + 65));
      x.setAttribute("onclick", "isTOF(this.id)");
      document.body.appendChild(x);
      }

      function isTOF(v) {
      alert(v);
      }





      But since you have a direct reference to the element already, rather than assign a string attribute in the HTML to be turned into a handler (which is basically eval in the form of an HTML attribute), it would be better to attach the listener properly using Javascript - which will make things easier, because then the id, if you set a variable to it beforehand, can simply be referenced again in the handler, rather than having to check this.id. In addition, you can often use dot notation rather than setAttribute, which is more concise and easier to read, so it's probably preferable in most cases:






      for (let i = 0; i < 26; i++) {
      const x = document.createElement("INPUT");
      x.type = 'button';
      const id = String.fromCharCode(i + 65);
      x.value = id;
      x.id = id;
      x.onclick = () => isTOF(id);
      document.body.appendChild(x);
      }

      function isTOF(v) {
      console.log(v);
      }








      share|improve this answer


























        2














        The problem is:



        x.setAttribute("onclick", "isTOF(self.id)");


        There's no variable named self in scope at that point. Perhaps you meant to use this, which would work:






        for (i = 0; i < 26; i++) {
        var x = document.createElement("INPUT");
        x.setAttribute("type", "button");
        x.setAttribute("value", String.fromCharCode(i + 65));
        x.setAttribute("id", String.fromCharCode(i + 65));
        x.setAttribute("onclick", "isTOF(this.id)");
        document.body.appendChild(x);
        }

        function isTOF(v) {
        alert(v);
        }





        But since you have a direct reference to the element already, rather than assign a string attribute in the HTML to be turned into a handler (which is basically eval in the form of an HTML attribute), it would be better to attach the listener properly using Javascript - which will make things easier, because then the id, if you set a variable to it beforehand, can simply be referenced again in the handler, rather than having to check this.id. In addition, you can often use dot notation rather than setAttribute, which is more concise and easier to read, so it's probably preferable in most cases:






        for (let i = 0; i < 26; i++) {
        const x = document.createElement("INPUT");
        x.type = 'button';
        const id = String.fromCharCode(i + 65);
        x.value = id;
        x.id = id;
        x.onclick = () => isTOF(id);
        document.body.appendChild(x);
        }

        function isTOF(v) {
        console.log(v);
        }








        share|improve this answer
























          2












          2








          2






          The problem is:



          x.setAttribute("onclick", "isTOF(self.id)");


          There's no variable named self in scope at that point. Perhaps you meant to use this, which would work:






          for (i = 0; i < 26; i++) {
          var x = document.createElement("INPUT");
          x.setAttribute("type", "button");
          x.setAttribute("value", String.fromCharCode(i + 65));
          x.setAttribute("id", String.fromCharCode(i + 65));
          x.setAttribute("onclick", "isTOF(this.id)");
          document.body.appendChild(x);
          }

          function isTOF(v) {
          alert(v);
          }





          But since you have a direct reference to the element already, rather than assign a string attribute in the HTML to be turned into a handler (which is basically eval in the form of an HTML attribute), it would be better to attach the listener properly using Javascript - which will make things easier, because then the id, if you set a variable to it beforehand, can simply be referenced again in the handler, rather than having to check this.id. In addition, you can often use dot notation rather than setAttribute, which is more concise and easier to read, so it's probably preferable in most cases:






          for (let i = 0; i < 26; i++) {
          const x = document.createElement("INPUT");
          x.type = 'button';
          const id = String.fromCharCode(i + 65);
          x.value = id;
          x.id = id;
          x.onclick = () => isTOF(id);
          document.body.appendChild(x);
          }

          function isTOF(v) {
          console.log(v);
          }








          share|improve this answer












          The problem is:



          x.setAttribute("onclick", "isTOF(self.id)");


          There's no variable named self in scope at that point. Perhaps you meant to use this, which would work:






          for (i = 0; i < 26; i++) {
          var x = document.createElement("INPUT");
          x.setAttribute("type", "button");
          x.setAttribute("value", String.fromCharCode(i + 65));
          x.setAttribute("id", String.fromCharCode(i + 65));
          x.setAttribute("onclick", "isTOF(this.id)");
          document.body.appendChild(x);
          }

          function isTOF(v) {
          alert(v);
          }





          But since you have a direct reference to the element already, rather than assign a string attribute in the HTML to be turned into a handler (which is basically eval in the form of an HTML attribute), it would be better to attach the listener properly using Javascript - which will make things easier, because then the id, if you set a variable to it beforehand, can simply be referenced again in the handler, rather than having to check this.id. In addition, you can often use dot notation rather than setAttribute, which is more concise and easier to read, so it's probably preferable in most cases:






          for (let i = 0; i < 26; i++) {
          const x = document.createElement("INPUT");
          x.type = 'button';
          const id = String.fromCharCode(i + 65);
          x.value = id;
          x.id = id;
          x.onclick = () => isTOF(id);
          document.body.appendChild(x);
          }

          function isTOF(v) {
          console.log(v);
          }








          for (i = 0; i < 26; i++) {
          var x = document.createElement("INPUT");
          x.setAttribute("type", "button");
          x.setAttribute("value", String.fromCharCode(i + 65));
          x.setAttribute("id", String.fromCharCode(i + 65));
          x.setAttribute("onclick", "isTOF(this.id)");
          document.body.appendChild(x);
          }

          function isTOF(v) {
          alert(v);
          }





          for (i = 0; i < 26; i++) {
          var x = document.createElement("INPUT");
          x.setAttribute("type", "button");
          x.setAttribute("value", String.fromCharCode(i + 65));
          x.setAttribute("id", String.fromCharCode(i + 65));
          x.setAttribute("onclick", "isTOF(this.id)");
          document.body.appendChild(x);
          }

          function isTOF(v) {
          alert(v);
          }





          for (let i = 0; i < 26; i++) {
          const x = document.createElement("INPUT");
          x.type = 'button';
          const id = String.fromCharCode(i + 65);
          x.value = id;
          x.id = id;
          x.onclick = () => isTOF(id);
          document.body.appendChild(x);
          }

          function isTOF(v) {
          console.log(v);
          }





          for (let i = 0; i < 26; i++) {
          const x = document.createElement("INPUT");
          x.type = 'button';
          const id = String.fromCharCode(i + 65);
          x.value = id;
          x.id = id;
          x.onclick = () => isTOF(id);
          document.body.appendChild(x);
          }

          function isTOF(v) {
          console.log(v);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 6:27









          CertainPerformance

          74.3k143659




          74.3k143659























              2














              I would use an event listener instead like so:






              function isTOF(e) {
              console.log("id:["+ this.id +"], value:["+ this.value +"]");
              }
              window.onload = function() {
              for(i = 0; i < 26; i++) {
              var x = document.createElement("INPUT");
              x.setAttribute("type", "button");
              x.setAttribute("value", String.fromCharCode(i + 65));
              x.setAttribute("id", String.fromCharCode(i + 65));
              x.addEventListener("click", isTOF, false);
              document.body.appendChild(x);
              }
              }








              share|improve this answer




























                2














                I would use an event listener instead like so:






                function isTOF(e) {
                console.log("id:["+ this.id +"], value:["+ this.value +"]");
                }
                window.onload = function() {
                for(i = 0; i < 26; i++) {
                var x = document.createElement("INPUT");
                x.setAttribute("type", "button");
                x.setAttribute("value", String.fromCharCode(i + 65));
                x.setAttribute("id", String.fromCharCode(i + 65));
                x.addEventListener("click", isTOF, false);
                document.body.appendChild(x);
                }
                }








                share|improve this answer


























                  2












                  2








                  2






                  I would use an event listener instead like so:






                  function isTOF(e) {
                  console.log("id:["+ this.id +"], value:["+ this.value +"]");
                  }
                  window.onload = function() {
                  for(i = 0; i < 26; i++) {
                  var x = document.createElement("INPUT");
                  x.setAttribute("type", "button");
                  x.setAttribute("value", String.fromCharCode(i + 65));
                  x.setAttribute("id", String.fromCharCode(i + 65));
                  x.addEventListener("click", isTOF, false);
                  document.body.appendChild(x);
                  }
                  }








                  share|improve this answer














                  I would use an event listener instead like so:






                  function isTOF(e) {
                  console.log("id:["+ this.id +"], value:["+ this.value +"]");
                  }
                  window.onload = function() {
                  for(i = 0; i < 26; i++) {
                  var x = document.createElement("INPUT");
                  x.setAttribute("type", "button");
                  x.setAttribute("value", String.fromCharCode(i + 65));
                  x.setAttribute("id", String.fromCharCode(i + 65));
                  x.addEventListener("click", isTOF, false);
                  document.body.appendChild(x);
                  }
                  }








                  function isTOF(e) {
                  console.log("id:["+ this.id +"], value:["+ this.value +"]");
                  }
                  window.onload = function() {
                  for(i = 0; i < 26; i++) {
                  var x = document.createElement("INPUT");
                  x.setAttribute("type", "button");
                  x.setAttribute("value", String.fromCharCode(i + 65));
                  x.setAttribute("id", String.fromCharCode(i + 65));
                  x.addEventListener("click", isTOF, false);
                  document.body.appendChild(x);
                  }
                  }





                  function isTOF(e) {
                  console.log("id:["+ this.id +"], value:["+ this.value +"]");
                  }
                  window.onload = function() {
                  for(i = 0; i < 26; i++) {
                  var x = document.createElement("INPUT");
                  x.setAttribute("type", "button");
                  x.setAttribute("value", String.fromCharCode(i + 65));
                  x.setAttribute("id", String.fromCharCode(i + 65));
                  x.addEventListener("click", isTOF, false);
                  document.body.appendChild(x);
                  }
                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 11 at 6:34

























                  answered Nov 11 at 6:29









                  Tigger

                  6,15432633




                  6,15432633






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246363%2fjavascript-string-undefined%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings