/    Sign up×
Community /Pin to ProfileBookmark

Javascript Form Input Question

Hi I’m sure this is a simple JavaScript function, but I’m still rather new to them..

The following code below displays letters that are inputted into the form field when typed.

The main objective is to get the word “test” to spell out backwards “tset” (Basically any character inserted from the keypad would input itself backwards).

The form outputs “hello” when inputted properly.

Any ideas anyone?

Thanks!

<html>

<head>

<center>
<script type = “text/javascript”>

function replaceChars() {
var temp = document.subform.text.value;

temp = temp.replace(/tset/gi, “hello”);

document.subform.text.value = temp;
}

</script>

</head>

<body>

<form name=”subform”>

<textarea rows=”8″ name=”text” cols=”48″ value=””></textarea>
<br><br>
<input type=button name=action value=”Change” onClick=”replaceChars(document.subform.text.value);”>

<br><br>

<table border=”1″ width=”284″ id=”table1″ height=”58″ bgcolor=”#FFFFFF”>
<tr>
<td align=”center” width=”70″><INPUT TYPE=”button” NAME=”t” VALUE=” t ” OnClick=”subform.text.value += ‘t'”></td>
<td align=”center” width=”70″><INPUT TYPE=”button” NAME=”e” VALUE=” e ” OnClick=”subform.text.value += ‘e'”></td>
<td align=”center” width=”70″><INPUT TYPE=”button” NAME=”s” VALUE=” s ” OnClick=”subform.text.value += ‘s'”></td>
<td align=”center” width=”70″><INPUT TYPE=”button” NAME=”t” VALUE=” t ” OnClick=”subform.text.value += ‘t'”></td>
</tr>
</table>

</form>

</center>

</body>

</html>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@PadonakAug 19.2007 — can you please ask it again in other words? i cant understand the question - what exactly do you want? (sorry im russian, bad english)
Copy linkTweet thisAlerts:
@Angry_Black_ManAug 19.2007 — i googled:

"reverse text" javascript[/quote]

here is the result of the search: see the search result titled "Q278 How can I reverse text in a form field?", which is the third result on the page.

http://www.google.com/search?hl=en&q=%22reverse+text%22+javascript&btnG=Google+Search

what youve done simply replaces "tset" (if the user inputs it that way) with the word hello. it does nothing to the order of the user input essentially; it on replaces text it IF it meets your replace regular expression.
Copy linkTweet thisAlerts:
@theflyingminstauthorAug 19.2007 — Sorry if I wasn't so clear, I'm having a b*tch of a time with this one. As the user clicks the keypad with the letters "t", "e", "s" "t", they should automatically type in backwards. Thanks for sending me those code snippets, it's just I'm having a hard time integrating it into the current code that I have.

Thanks to both of you for responding. Awesome google search items!!
Copy linkTweet thisAlerts:
@Angry_Black_ManAug 19.2007 — instead of doing

subform.text.value += 't'

do

subform.text.value = 't' + subform.text.value

and so on down the line
Copy linkTweet thisAlerts:
@theflyingminstauthorAug 19.2007 — Yes! Thank you, you're a rock star!
Copy linkTweet thisAlerts:
@PadonakAug 19.2007 — im not sure that my solution is what you need but anyway take a look at this [url=http://fisioterapiautebo.com/padonak/webdeveloper/text_reverse.htm][b]link[/b][/url]
×

Success!

Help @theflyingminst spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...