Results 1 to 4 of 4

Thread: [RESOLVED] undefined???

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Resolved [RESOLVED] undefined???

    I get an error message "undefined" for the following script..

    any help?

    thanks

    VB Code:
    1. <html><head>
    2. <script>
    3. var h=0;
    4. function yaz()
    5. {
    6. for(h=0;h<=6;h++)
    7. {
    8. var rno=(Math.floor(Math.random()*50)+1);
    9. document.getElementById('oda').innerHTML=rno[h];
    10. }
    11. }
    12. </script></head><body>
    13. <div id="oda">......</div>
    14. <form>
    15. <input type=button value="print the rand nums" onClick="yaz()">
    16. </form></body></html>

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: undefined???

    rno is not an array. Try removing the [h] in innerHTML=rno[h];

  3. #3

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: undefined???

    still get an error saying..
    "document.getElementById("...").innerHTML..." is NULL or not an object

    it prints only one num...where as I need six nums..
    so how shall I fix it?
    thanks
    Last edited by merhaba; Jan 18th, 2006 at 11:52 AM.

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: undefined???

    Not sure why you are getting the error. It ran for me in IE6.0.

    It actually prints all 7 (not 6) numbers generated. The problem is that you only see the last number because:
    1) you replace the innerhtml each pass through the loop, and
    2) it executes too fast to see each change.

    If you only want 6 numbers then remove the '=' from 'h<=6;'.

    Take a look at this
    Code:
    <html>
     <head>
      <script>
       var h=0;
       function yaz()
        {
         document.getElementById('oda').innerHTML = '';
         for (h=0;h<=6;h++)
             {
              var rno = (Math.floor(Math.random()*50)+1);
              document.getElementById('oda').innerHTML += rno + '<br>';
             }
        }
      </script>
     </head>
     <body>
      <div id="oda">......</div>
      <form>
       <input type=button value="print the rand nums" onClick="yaz()">
      </form>
     </body>
    </html>

Posting Permissions

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



Click Here to Expand Forum to Full Width