Results 1 to 10 of 10

Thread: Hmm...Cap Generator?

  1. #1
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hmm...Cap Generator?

    Im wondering if its possible to make a Cap generator.

    Say I have something like this:
    Code:
    <input type="text" id="pass"><br />
    <input type="button" value="Click" onclick="Rawr();"><br />
    <div id="caps"></div>
    
    <script>
    function Rawr(){
    var x = document.getElementById("pass").value;
    document.getElementById("caps").innerHTML = x;
    };
    </script>
    when you type in a word in the input box, then click the button, it would show just the exact same thing you put in the input box.

    How would I make it so that every time you click the button, you get the same word, but with different capital letters?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    If highlighted text is true, it will go to uppercase, and if its false, it will go to lowercase.
    Code:
    <input type="text" id="pass"><br />
    <input type="button" value="Click" onclick="Rawr(true);"><br />
    <div id="caps"></div>
    
    <script>
    function Rawr(upper){
    var x = document.getElementById("pass").value;
    document.getElementById("caps").innerHTML = (upper == true) ? x.toUpperCase() : x.toLowerCase();
    }
    </script>
    And this one is completely random:
    Code:
    <input type="text" id="pass"><br />
    <input type="button" value="Click" onclick="Rawr(Math.floor(Math.random()*2));"><br />
    <div id="caps"></div>
    
    <script>
    function Rawr(upper){
    var x = document.getElementById("pass").value;
    document.getElementById("caps").innerHTML = (upper == true) ? x.toUpperCase() : x.toLowerCase();
    }
    </script>
    Jeremy | jfein.net

  3. #3
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That isn't exactly what im looking for...

    Say you put test in the input box.
    Then you click the button and you get tESt.
    Click it again you get Test
    Click it again and you get TeST

    See what I mean? The letters of the word that you typed in the input box will be different caps each time you click the button.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    So absolutely random?
    Jeremy | jfein.net

  5. #5
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yep. So that the caps arn't the same each time.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here you go:
    Code:
    <input type="text" id="pass"><br />
    <input type="button" value="Click" onclick="Rawr();"><br />
    <div id="caps"></div>
    
    <script>
    function Rawr(upper){
    var x = document.getElementById("pass").value;
    var arrayX = new Array();
    var xreturn = "";
    for(i=0;i<x.length;i++){
    arrayX[i] = Math.floor(Math.random()*2);
    if(arrayX[i] == 0){
    xreturn += x.substr(i,1).toUpperCase();
    } else {
    xreturn += x.substr(i,1).toLowerCase();
    }
    }
    document.getElementById("caps").innerHTML = xreturn;
    }
    </script>
    Jeremy | jfein.net

  7. #7
    Join Date
    Dec 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks

    Now this might be harder, not sure, sorry if I asking to much.

    Can you tell me how I can make that so it will not be random, but it will show all the possible cap combinations for that word?

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't think so... Its very hard. A word like: dictionary could take days...
    Jeremy | jfein.net

  9. #9
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Agent Moose View Post
    Thanks

    Now this might be harder, not sure, sorry if I asking to much.

    Can you tell me how I can make that so it will not be random, but it will show all the possible cap combinations for that word?
    like nile said a word like dictionary could crash the browser because there are 2^10 (1,024) possibilities. i suggest you stick with the random one. you could make it that every time you press it you get a different one, but that is it.
    Code:
    <input type="text" id="pass"><br />
    <input type="button" value="Click" onclick="Rawr();"><br />
    <div id="caps"></div>
    
    <script>
    var a=new Array();
    var t=50; //number of tries
    function Rawr(upper){
    var x = document.getElementById("pass").value;
    var arrayX = new Array();
    var xreturn = "";
    for(i=0;i<x.length;i++){
    arrayX[i] = Math.floor(Math.random()*2);
    if(arrayX[i] == 0){
    xreturn += x.substr(i,1).toUpperCase();
    } else {
    xreturn += x.substr(i,1).toLowerCase();
    }
    }
    if (a.inArray(xreturn)) {
    t--;
    if (t>=1) {
    Rawr();
    } else {
    document.getElementById("caps").innerHTML="no  more tries left";
    }
    } else {
    a[]=xreturn;
    document.getElementById("caps").innerHTML = xreturn;
    }
    }
    Array.prototype.inArray = function (value) {
    	var i;
    	for (i=0; i < this.length; i++) {
    		if (this[i] === value) {
    			return true;
    		}
    	}
    	return false;
    };
    </script>
    Last edited by Master_script_maker; 06-30-2008 at 01:21 AM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  10. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Your script does not work.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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