Web Analytics Made Easy -
StatCounter I need help with something - CodingForum

Announcement

Collapse
No announcement yet.

I need help with something

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I need help with something

    Currently I am creating a web site that is slightly more interactive than the average web site, tables that you can move around the screen, a sort of 3d thing...

    I don't really need help with any of that what I need help with is something that should be quite simple but isn't, at least for me any way.

    What I need is a script that contains a list of differing words the script would read these words then put a word into a text box randomly or in a series and then once you refreshed the page or pressed a button it would come up with a differing word.

  • #2
    Try something like so:
    Code:
    <script language="JavaScript">
    
    var word = new Array()
    
    word[0] = "Hi";
    word[1] = "my";
    word[2] = "name";
    word[3] = "is";
    word[4] = "Fred";
    
    var w = word.length;
    var selectWord = Math.round(Math.random() * (w - 1));
    
    function giveWord() {
      document.write(word[selectWord]);
    }
    giveWord();
    </script>

    Comment


    • #3
      Thank you Antoniohawk, however I have already done that, what I want to know is how do you put that random value into a word box.

      for example:

      <td class="PPRLabelText">Password&nbsp;</td>
      <td><input type="text" name="wordbox" maxlength="16" class="PPRField" size="25" tabindex="2" autocomplete="ON"></td>

      Comment


      • #4
        Originally posted by Teal
        Thank you Antoniohawk, however I have already done that, what I want to know is how do you put that random value into a word box.
        Then change document.write(word[selectWord]);
        To target your wordbox.

        eg:
        document.formName.wordbox.value = word[selectWord];

        And use either an onload event handler or a button to populate the wordbox with the random value.

        .....Willy

        Comment


        • #5
          rounding the random function makes it unrandom, floor it instead

          Comment

          Working...
          X