Click to See Complete Forum and Search --> : Question about "tExT lIkE tHiS"


Jona
01-23-2003, 01:39 PM
I forgot the code to make TeXt LiKe ThIs. It's something like...

var msg = "the text to make up and down"
for(i=0; i<msg.length; i++)
// I forget the rest...

Anyone know it, or can help?

Thanks :)

khalidali63
01-23-2003, 01:47 PM
I hope this helps

cheers

Khalid


<script type="text/javascript">

function process(){
var frm = document.form1;
var str = frm.txt1.value;
var messageStr = "";
for(n=0;n<str.length;n++){
var chr = str.charAt(n);
if((n%2)==0){
messageStr+=chr.toUpperCase();
}else{
messageStr+=chr.toLowerCase();
}
}
document.getElementById("message").innerHTML = messageStr;
}

</script>
</head>

<body>
<form name="form1">
<input type="Text" name="txt1"></input>
<input type="Button" value="process" onclick="process();"></input>
</form><br><br>
<div id="message"></div>

Charles
01-23-2003, 01:47 PM
<script type="text/javascript">
<!--
String.prototype.toMixedCase = function () {
var a = this.toLowerCase().split('');
for (j=0;j<a.length;j+=2) {a[j] = a[j].toUpperCase()};
return a.join('');
}

alert('Phiv hatecra, scrar muvali pa depivius imedr.'.toMixedCase())
// -->
</script>

Jona
01-23-2003, 01:53 PM
Thanks, guys. Charles, you got it! When I used the script, though, I used for(x) instead of for(j), but the function is just about the same. Let me test it to make sure it works.

kalidalid63, that code probably works, but I wansn't exactly using forms. I was talking about a variable holding the value of the message.

khalidali63
01-23-2003, 02:04 PM
kalidalid63, that code probably works, but I wansn't exactly using forms. I was talking about a variable holding the value of the message.


I know you were not,but that was just to display the functionality...you'd get varaible value from somewhere right..or you think variable will get value by itself some how.

in the code that posted above

var str = frm.txt1.value;


creates a variable.......that holds a string in it.
And it does work.


;)

Just a bit of calrification

cheers

Khalid

Jona
01-23-2003, 02:11 PM
It did work.

Yes, khaldidad63, but I wasn't directing my question towards forms, I replaced Charles' code with document.write() instead of alert().

I knew it was the split() and join() functions..

BTW, what's really cool about this is I can change, "split(' ')" to, "split('a')" and make it join with a different letter.

This also reminds me of a code I was going to do.

Two select boxes with all of the letters of the alphabet inside of each. Below, a textarea, a button, and another textarea. If selectbox1's option A is selected, split('a') (from textarea1) to selectbox2's option's value. Put the result into textarea2, onClick button1.:p

khalidali63
01-23-2003, 02:15 PM
Happy JavaScripting..
Its fun isnt' it .

cheers

Khalid

Jona
01-23-2003, 02:19 PM
Are you kidding? I love JavaScripting!!! Pardon the obnoxious attitude, please. But it is true... :D