Textbox to display function JavaScript -


i'm having issue first project semester. using javascript i'm supposed create magic 8 ball simulator. simulator needs button that says "shake it" which, when clicked, displays random saying getsaying() function in read textbox. little lost. how go specifying textbox saying displayed in?

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title>magic 8 ball!</title> <style type="text/css"> /*styles go here*/   </style> </head> <body>  <button type="button" onclick="show()">shake it!</button>   <script type="text/javascript">          function show() {             document.write(getsaying());         }          function getsaying() {              var pool = ["it certain", "it decidedly so", "without doubt",                          "yes definitely", "you may rely on it", "as see it, yes",                         "most likely", "outlook good", "yes", "signs point yes",                          "reply hazy try again", "ask again later", "better not tell now",                          "cannot predict now", "concentrate , ask again", "don't count on it",                          "my reply no", "my sources no", "outlook not good", "very doubtful"];              return (pool[math.floor(math.random()*pool.length)]);         }  </script>   </body> </html> 

you have use document.getelementbyid() input , set value.

working example here

<button type="button" onclick="show()">shake it!</button> <input id="saying" />  <script type="text/javascript">      function show() {         document.getelementbyid("saying").value = getsaying();     }      function getsaying() {          var pool = ["it certain", "it decidedly so", "without doubt",                      "yes definitely", "you may rely on it", "as see it, yes",                     "most likely", "outlook good", "yes", "signs point yes",                      "reply hazy try again", "ask again later", "better not tell now",                      "cannot predict now", "concentrate , ask again", "don't count on it",                      "my reply no", "my sources no", "outlook not good", "very doubtful"];          return (pool[math.floor(math.random()*pool.length)]);     }  </script> 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -