Author Topic: Can anyone help me with this bit of javascript?  (Read 677 times)

Offline PspKicks316

  • Acidmods Alumni
  • Mad Bomber
  • *
  • Posts: 5709
  • Post quality +5/-4
  • Gender: Male
Can anyone help me with this bit of javascript?
« on: December 21, 2008, 09:15:03 AM »
Ok well, I'm trying to make a script that takes whatever it put into the text box and output replaced text.
For example, I type in "a" (no quotes) and it replaces the textbox value with "s" (no quotes) (or off to the side of the box if easier).

I know about the var.replace(/a/g,s) string, but I've tried everything and for the life of me can't figure out how to grab the value of the text box and replace it with the replaced value...

I've tried this but what am I doing wrong??

Code: [Select]
<html>
<head>
<script language="JavaScript">
function encodeText() {
var decoded = form.encode.value;
var encoded = decoded.replace(/a/g,s,/b/g,n,/c/g,v,/d/g,f,/e/g,r,/f/g,g,/g/g,h,/h/g,j,/i/g,o,/j/g,k,/k/g,l,/l/g,";",/m/g,",")
   form.encode.value = encoded;
}
</script>
</head>
<body>
<form name="encode" action="" method="get">
<input type="text" name="encode" value="">
    <input type="button" name="encode" value="Encode" onClick="encodeText()">
</form>
</body>
</html>

And one more question, do I have the decoded.replace() set up correctly? I know about only using 1 variable to replace, but I'm not sure if I have it right for more than one. And I think I can't use the quotes around the , and ; so how would I replace m with , and replace l with ; ??

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal