PDA

View Full Version : Certain Character Code Replacer



Rockonmetal
03-03-2007, 12:10 AM
Ok
I want to have a little form. Where I enter a line which looks like this:
emailto=smiesian@comcast.net&FirstName=BOB&LastName=BOB&Age=999&Username=IHATEBOB&UserMame=PASSWORD
ok
I want it to look like this:
<firstname>BOB</firstname><lastname>BOB</lastname>...

I am thinking i have seen something like this in a text area where i put it into and i press a button and it changes it.

THIS IS ONLY FOR ME! NOT FOR MY VIEWERS! THANKS!!! HTML and Javascript or if you can, Html , or just javascript. Here are the things i want to change:
& becomes <
= becomes />
ok??

is that hard?? (I hope not) thanks people really alot for just reading this...

jscheuer1
03-03-2007, 04:54 PM
Could need refinement, I'm not certain if I understood your requirements:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Custom Text Transform Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function eq_amp(str){
var str=str.replace(/&$/g, '');
while(/&([^=]*)=([^&^<]*)(&|$|<)/.test(str))
str=str.replace(/&([^=]*)=([^&^<]*)(&|$|<)/g, '<$1>$2</$1>$3');
return str;
}
</script>
</head>
<body>
<form action="#">
<input name="test" type="text" size="100" value="smiesian@comcast.net&FirstName=BOB&LastName=BOB&Age=999&Username=IHATEBOB&UserMame=PASSWORD"><br>
<input type="button" onclick="this.form['test'].value=eq_amp(this.form['test'].value)" value="Go!"
</body>
</html>