Click to See Complete Forum and Search --> : Spliting Strings and Storing Data


S1L3NC3
10-05-2003, 12:04 PM
Alright, i want to receive input in a textarea, click an encode button, have it split the text into individual characters i got this too work so far) then store every character into an array so that i can call them back indiviually and run them through an alogrythim for encoding.

I just used y=x.split("") to split it into every letter.
I need to know how to get it to store every returned value into an array plz.

Heres my code.



<html>
<head>
<script language="JavaScript" type="text/javascript">
function doit()
{
var x,y;
x=document.ioboxes.input.value;
<!-- ENCODE HERE AND STORE RESULT IN Y -->
y=x.split("")

<!-- FINAL OUTPUT -->
document.ioboxes.output.value=y;
}
</script>
</head>
<body bgcolor="gray" text="white">
<div align="center">
<BR>
<p>Encoder/Decoder</p>
<form name="ioboxes">
<textarea cols="50" rows="8" name="input"></textarea>
<BR><BR>
<input type="button" value="Encode" name="button1" onClick="doit()">
<input type="button" value="Decode" name="button2" onClick="undoit()">
<BR><BR>
<textarea cols="50" rows="8" name="output"></textarea>
</form>
</body>
</html

mahugl
10-05-2003, 12:11 PM
if I am not mistaken isn't x your array.
since you split it.
To access it you use x[0] x[1] or
i=0 x[i]

S1L3NC3
10-05-2003, 12:18 PM
I tried throwing this in

y=x.split("")
alert(x[0]);

and it just alerts "Undefined".
So i dont know :confused:

Charles
10-05-2003, 12:23 PM
Given y=x.split("") y is an Array and x remains a String.

S1L3NC3
10-05-2003, 12:24 PM
Ah hA! I figured it out, i set it to variable Y so Y is my array. I couldnt have done it without your hint though. So thank you very much!

S1L3NC3
10-05-2003, 12:28 PM
Guess i missed your post charles, thank you too.

Also, is there a javascript command that swaps input for a pre-determined set? Kinda of like a key for a code. Or is there a Base64 Conversion command in JavaScript?