Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Location
    unconventional
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up 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
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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>

  • #3
    New to the CF scene
    Join Date
    Feb 2004
    Location
    unconventional
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rounding the random function makes it unrandom, floor it instead


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •