Loading...
  1. Dismiss Notice
  2. Dismiss Notice
  3. Dismiss Notice
  4. Dismiss Notice
  5. If this is your first visit, you may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

java to html

Discussion in 'Programming Lounge' started by snic, Dec 17, 2013.

Thread Status:
Not open for further replies.
  1. snic

    snic Respected Member

    Joined:
    Aug 23, 2010
    Messages:
    3,486
    Likes Received:
    1,329
    Trophy Points:
    393
    Location:
    Dark side of the moon <3
    Well hello there in the first place, if there are some programmers out there i need a little help. I've got javascript code that i need to put into html here it goes :
    function makeid() {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


    for( var i=0; i < 5; i++ )
    text += possible.charAt(Math.floor(Math.random() * possible.length));


    return text;
    }


    document.getElementById('random-number').innerHTML = makeid();

    and the html version of that ( what software show me) is this <div id="random-number"></div>, but html code does not work while java does, so how can i make it work? :D
     
  2. Razor

    Razor Master of Disguise Forum Legend

    Joined:
    Oct 14, 2010
    Messages:
    3,356
    Likes Received:
    2,072
    Trophy Points:
    463
    Location:
    Sofia, Bulgaria
    Copy-pasted a documentation about getElementById (I don't know much of HTML or JavaScript) and ended up with this (working.. I guess):

    Code:
    <!DOCTYPE html>
    <html>
    <head>
      <title>getElementById example</title>
      <script>
      function makeid() {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789";
    
    
    for( var i=0; i < 5; i++ )
    text += possible.charAt(Math.floor(Math.random() * possible.length));
    
    
    document.getElementById("para1").innerHTML = text;
    }
      </script>
    </head>
    <body>
      <p id="para1">Some text here</p>
      <button onclick="makeid();">blue</button>
    </body>
    </html>
     
    1 person likes this.
  3. snic

    snic Respected Member

    Joined:
    Aug 23, 2010
    Messages:
    3,486
    Likes Received:
    1,329
    Trophy Points:
    393
    Location:
    Dark side of the moon <3
    oh thank you very much :)
     
Thread Status:
Not open for further replies.

Share This Page