PDA

View Full Version : Hmm...Cap Generator?



Agent Moose
06-29-2008, 11:53 PM
Im wondering if its possible to make a Cap generator.

Say I have something like this:

<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?

Nile
06-30-2008, 12:01 AM
Here:
If highlighted text is true, it will go to uppercase, and if its false, it will go to lowercase.


<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:


<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>

Agent Moose
06-30-2008, 12:05 AM
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.

Nile
06-30-2008, 12:07 AM
So absolutely random?

Agent Moose
06-30-2008, 12:14 AM
Yep. So that the caps arn't the same each time.

Nile
06-30-2008, 12:18 AM
Here you go:


<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>

Agent Moose
06-30-2008, 12:24 AM
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?

Nile
06-30-2008, 12:31 AM
I don't think so... Its very hard. A word like: dictionary could take days...

Master_script_maker
06-30-2008, 01:16 AM
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.
<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>

Nile
06-30-2008, 03:33 AM
Your script does not work.