www.webdeveloper.com
Results 1 to 3 of 3

Thread: can anyone help me about random text in textbox

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    can anyone help me about random text in textbox

    <html lang="en">
    <script language="javascript" type="text/javascript">
    function randomString() {

    var chars ="";

    var string_length = 4;

    var randomstring = '';

    for (var i=0; i<string_length; i++)
    {
    var rnum = Math.floor(Math.random() * chars.length);
    randomstring += chars.substring(rnum,rnum+1);
    }

    document.randform.randomfield.value = randomstring;
    }
    </script>

    <form name="randform">
    <input type="button" value="click to text shuffle" onClick="randomString();">&nbsp;
    <input type="text" name="randomfield" value="">

    </form>
    </html>


    sample.jpgsample.jpg

  2. #2
    Join Date
    Aug 2013
    Posts
    56
    Code:
    <!--Delete this line of code: http://www.icode4u.tk Code CHECK-->
    <html lang="en">
    <script language="javascript" type="text/javascript">
    function randomString() {
    var choose = Math.floor((Math.random()*10)+1); //Change 10 to the ammount of else/if statements you are going to add
    var two = prompt("Word you want to sHufFlE?");
    if (two.length <  1) {
    alert(two);
    }
    if (two.length === 2) {
    if (choose < 1) {
    alert(two[0] + two[1]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[1]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[1]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[1] + two[0]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    if (two.length === 3) {
    if (choose < 1) {
    alert(two[0] + two[2] + two[1]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[2] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[2] + two[1]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[2] + two[1]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0] + two[2]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[2] + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[2] + two[1] + two[0]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[2] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    if (two.length === 4) {
    if (choose < 1) {
    alert(two[0] + two[2] + two[3] + two[1]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[3] + two[2] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[3] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[2] + two[1]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[2] + two[1] + two[3]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[3] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0] + two[3] + two[2]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[3] + two[2] + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[2] + two[1] + two[3] + two[0]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[2] + two[3] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    if (two.length === 5) {
    if (choose < 1) {
    alert(two[0] + two[2] + two[3] + two[4] + two[1]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[3] + two[4] + two[2] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[3] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[4] + two[2] + two[1]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[2] + two[4] + two[1] + two[3]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[3] + two[4] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0] + two[4] + two[3] + two[2]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[3] + two[2] + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[2] + two[1] + two[3] + two[0]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[2] + two[3] + two[4] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    if (two.length === 6) {
    if (choose < 1) {
    alert(two[0] + two[2] + two[3] + two[5] + two[4] + two[1]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[3] + two[4] + two[2] + two[5] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[5] + two[3] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[4] + two[2] + two[1] + two[5]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[2] + two[4] + two[1] + two[3] + two[5]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[3] + two[5] + two[4] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0] + two[5] + two[4] + two[3] + two[2]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[3] + two[5] + two[2] + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[2] + two[1] + two[3] + two[0] + two[5]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[2] + two[3] + two[4] + two[5] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    //KEEP ADDING!! 48hours of hard work and it will be awesome!
    //----------------------------------------------------------------------
    if (two.length === 7) {
    if (choose < 1) {
    alert(two[0] + two[2] + two[3] + two[5] + two[4] + two[6] + two[1]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[3] + two[4] + two[2] + two[5] + two[6] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[6] + two[5] + two[3] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[6] + two[4] + two[2] + two[1] + two[5]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[6] + two[2] + two[4] + two[1] + two[3] + two[5]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[3] + two[5] + two[4] + two[6] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0] + two[5] + two[4] + two[3] + two[2]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[3] + two[5] + two[6] + two[2] + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[2] + two[1] + two[3] + two[6] + two[0] + two[5]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[2] + two[3] + two[4] + two[5] + two[6] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    //EXAMPLE for words with 8 characters:
    if (two.length ===  8) {
    if (choose < 1) {
    alert(two[0] + two[2] + two[3] + two[5] + two[4] + two[6] + two[1] + two[7]); //You can add more 
    } else if (choose < 2) {
    alert(two[1] + two[3] + two[4] + two[2] + two[7]  + two[5] + two[6] + two[0]); //You can add more 
    } else if (choose < 3) {
    alert(two[2]  + two[0] + two[6] + two[5] + two[7]  + two[3] + two[0] + two[1]); //You can add more 
    } else if (choose < 4) {
    alert(two[3] + two[0] + two[6] + two[7]  + two[4] + two[2] + two[1] + two[5]); //You can add more 
    } else if (choose < 5) {
    alert(two[0] + two[6] + two[2] + two[7]  + two[4] + two[1] + two[3] + two[5]); //You can add more 
    } else if (choose < 6) {
    alert(two[2] + two[1] + two[3] + two[5] + two[7]  + two[4] + two[6] + two[0]); //You can add more 
    } else if (choose < 0) {
    alert(two[6] + two[1] + two[0] + two[7]  + two[5] + two[4] + two[3] + two[2]); //You can add more 
    } else if (choose < 8) {
    alert(two[4] + two[3] + two[5] + two[6] + two[2] + two[7]  + two[0] + two[1]); //You can add more 
    } else if (choose < 9) {
    alert(two[4] + two[2] + two[1] + two[3] + two[7]  + two[6] + two[0] + two[5]); //You can add more 
    } else if (choose < 10) {
    alert(two[1] + two[2] + two[3] + two[4] + two[7]  + two[5] + two[6] + two[0]); //You can add more 
    } //Add extra else/if statement if you want, EVERY EXTRA ELSE/IF = CHANGING 10 AT MATH.RANDOM WITH 1 MORE
    else {
    alert("MEEEEEEEEEEEP");
    }
    }
    //STOP: EXAMPLE for words with 8 characters
    //If you want that your shuffler can also shuffle numbers of 9, add "+ two[8]" without "" to a new block, (copy/paste the one for a length of 8 and add + two[8] 
    };
    //DELETE THIS PART:
    if (two > 8) {
    alert("You need to make a extra code of block for words with an ammount of this character");
    }
    //DELETE THE ABOVE PART
    </script>
    <!--I used prompt cause I hadn't many time... You can do it with this at well with some changes! :)-->
    <form name="randform">
    <input type="button" id="input" value="click to text shuffle" onClick="randomString();">&nbsp;
    <input type="text" id="output" name="randomfield" value="">
    
    </form>
    <!--A PART FOR JOKE-->
    <a href="http://www.icode4u.tk/forum"><div style="width:500px; height:500px; background-color:#FF6600; color:#FFFFFF; position:absolute; top:125px; left:125px; font-family:Arial; font-size:25px;">Liked my help??? Join iCode4U forum for the best coding & technology discussions and HELP!!! (Click here)</div>
    <!--A PART FOR JOKE-->
    </html>
    <!--I HOPE YOU LIKE IT-->
    Copy/paste and test it here: http://www.csgnetwork.com/htmlcodetest.html

    Add block of codes for higher characters.

    Because this code only accepts words of 8 characters or lower, not higher, add more block of codes (like example for 8) and it will work also for higher characters! :P

  3. #3
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    373
    This is one idea:
    Code:
      var Characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZOI"
      var PassWord=""
      for (var i=0; i < 8; i++) {
        var rnd = Math.floor(Math.random() * parm) + (parm == 52? 10 : 0) ;
        PassWord = PassWord + Characters.charAt(rnd);
      }
    It's from a simple password generator.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles