javascript - Trying to add a link to open a 'steam://run/' link to a random word array -


so i'm messing creating random word picker pick steam game library, want add 'launch' link each random word. heres code;

    <html> <head>      <link rel="stylesheet" type="text/css" href="steam_gen_style.css">       <title>untitled</title> <script language="javascript"> <!-- // use following variable specify // number of random words var numberofwords = 28  var words = new buildarray(numberofwords)  // use following variables // define random words: words[1] = "ark: survival evolved/346110" words[2] = "portal 2/620" words[3] = "left 4 dead 2/550" words[4] = "cs:go/730" words[5] = "and yet moves/18700" words[6] = "bridge constructer/250460" words[7] = "bridge constructer medieval/319850" words[8] = "half-life 2/220" words[9] = "gta v/271590" words[10] = "antichamber/219890" words[11] = "world of goo/22000" words[12] = "super meat boy/40800" words[13] = "hotline miami/219150" words[14] = "metro: last light/287390" words[15] = "gta iv/12210" words[16] = "oddworld: new'n'tasty/314660" words[17] = "tug" words[18] = "trials evo" words[19] = "super hotline miami" words[20] = "outlast" words[21] = "besiege" words[22] = "next car game" words[23] = "rust" words[24] = "garry's mod" words[25] = "planetary annihilation" words[26] = "skyrim" words[27] = "minecraft" words[28] = "the forest"   function buildarray(size){ this.length = size (var = 1; <= size; i++){ this[i] = null} return }  function pickrandomword(frm) { var rnd = math.ceil(math.random() * numberofwords);  var index = words[rnd].indexof("/");  frm.wordbox.value = words[rnd].substring(0, index); var link = document.getelementbyid("gamelink"); var str = words[rnd].substring(index + 1, words[rnd].length); link.innerhtml = "<a href='steam://run/" + str + "'>click</a>"; }  // display word inside text box frm.wordbox.value = words[rnd] } //-->  </script>  <body>   <div id="top"></div> <header id="header">   <h1> today play </h1>    <form name="wordform" id="box">     <input    type=text size=30 name="wordbox" id="output"><br>     <input type=button id="button" onclick="pickrandomword(document.wordform)" value="click here random word">    </form> <p>link game: </p> <p id="gamelink"></p>  </header>  </body> </html> 

i've tried few things stuck, way, i've never done java know little bit of html, i'm messing around learn things!

well if want link generated based on game selected can add below 2 lines @ end of pickrandomword(),

 var link = document.getelementbyid("gamelink");  link.innerhtml = "<a href='steam://run/'"+words[rnd]+">"+words[rnd]+"</a>"; 

now add 2 more html lines after form,

<p>link game: </p> <p id="gamelink"></p> 

update: need have numbers 346110, 620 stored somewhere can access them depending on game select. asked example, here have come with.

here demo

suppose append numbers along name of game as,

 words[1] = "ark: survival evolved/346110";  words[2] = "portal 2/620"; 

now change pickrandomword() function as,

    function pickrandomword(frm) {         var rnd = math.ceil(math.random() * numberofwords);          var index = words[rnd].indexof("/");          frm.wordbox.value = words[rnd].substring(0, index);         var link = document.getelementbyid("gamelink");         var str = words[rnd].substring(index + 1, words[rnd].length);         link.innerhtml = "<a href='steam://run/" + str + "'>click</a>";     } 

update2: having problems parenthesis , not advisable write javascript statements without semi-colon(;). copy , paste below code is,

<script>     var numberofwords = 28      var words = new buildarray(numberofwords)      words[1] = "ark: survival evolved/346110"     words[2] = "portal 2/620"     words[3] = "left 4 dead 2/621"     words[4] = "cs:go/622"     words[5] = "and yet moves/622"     words[6] = "bridge constructer/6203"     words[7] = "bridge constructer medieval/6520"     words[8] = "half-life 2/6290"     words[9] = "gta v/6020"     words[10] = "antichamber/6250"     words[11] = "world of goo/6820"     words[12] = "super meat boy/6290"     words[13] = "hotline miami/61020"     words[14] = "metro: last light/62110"     words[15] = "gta iv/67620"     words[16] = "oddworld: new'n'tasty/62870"     words[17] = "tug/687820"     words[18] = "trials evo/6120"     words[19] = "super hotline miami/60"     words[20] = "outlast/690"     words[21] = "besiege/62900"     words[22] = "next car game/62023"     words[23] = "rust/620879"     words[24] = "garry's mod/626750"     words[25] = "planetary annihilation/6260"     words[26] = "skyrim/6276870"     words[27] = "minecraft/656520"     words[28] = "the forest/5620"      function buildarray(size) {         this.length = size         (var = 1; <= size; i++) {             this[i] = null         }         return     }      function pickrandomword(frm) {         var rnd = math.ceil(math.random() * numberofwords);          var index = words[rnd].indexof("/");          frm.wordbox.value = words[rnd].substring(0, index);         var link = document.getelementbyid("gamelink");         var str = words[rnd].substring(index + 1, words[rnd].length);         link.innerhtml = "<a href='steam://run/" + str + "'>click</a>";     } </script> <body>     <div id="top"></div>     <header id="header">          <h1> today play shit out of </h1>          <form name="wordform" id="box">             <input type=text size=30 name="wordbox" id="output">             <br>             <input type=button id="button" onclick="pickrandomword(document.wordform)" value="click here random word">         </form>         <p>link game:</p>         <p id="gamelink"></p>     </header> </body> 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -