1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pls help me fix my javascript code...

Discussion in 'HTML & JavaScript' started by xbryan, Mar 27, 2016.

  1. xbryan

    xbryan Senior Member

    Joined:
    Jul 12, 2015
    Messages:
    890
    Likes Received:
    214
    what i want to do is.
    var a[5randomnumber] = document.createElement("a");
    a[5randomnumber].href = "www.link.com/randomletters&numbers";

    example, ignore the message with ( )

    var a91268 <- (here as you can see, its 5 random number) = document.createElement("a");
    a91268 <- (same thing here) .href = "www.google.com/ahasxdhahsdxa27323hasxehahwexhaweh238283awxeh";
    this is what i want to do but i am here 20 mins searching on google but can't find answer :|

    please help a noob fix the code thanks.
     
  2. duca

    duca Registered Member

    Joined:
    Sep 18, 2008
    Messages:
    67
    Likes Received:
    17
    You can use something like this:

    Code:
    <script>
    var my_variable = 'a' + (Math.floor(Math.random()*90000) + 10000);
    my_variable = document.createElement("a");
    my_variable.href = "http://www.google.com/ahasxdhahsdxa27323hasxehahwexhaweh238283awxeh";
    </script>
     
  3. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    use the window object:
    Code:
    var name =  'a'+Math.round( Math.random()*99999 );
    window[ name ] = document.createElement("a");
    window[ name ].href =  "www.link.com/randomletters&numbers";
    
     
  4. living2xl

    living2xl Jr. VIP Jr. VIP

    Joined:
    Dec 9, 2011
    Messages:
    1,641
    Likes Received:
    366
    Occupation:
    Sippin dat juice - Shout it louder!
    Location:
    Not sleeping!
    Home Page:
    There are many tools available to get faults in programming.
    Why don't you try them? You can search on Google for getting good tools for it.
    You can find offline and online tools for it.