Click to See Complete Forum and Search --> : input in textarea display in text box ...
Code One
05-17-2003, 02:24 AM
Hello, I was wondering if anyone knew how to type a character in a textarea and have its value displayed in the textarea and also in a text box (both on the same page)?
Any help would be appreciated . . . thanks.
Code One
AdamGundry
05-17-2003, 02:53 AM
Something like this?
<input type="text" id="textbox">
<textarea id="textarea" onkeypress="CopyChar(event);"></textarea>
<script type="text/javascript">
function CopyChar(event){
if (event.which){
keyChar = String.fromCharCode(event.which);
} else {
keyChar = String.fromCharCode(event.keyCode);
}
document.getElementById('textbox').value = document.getElementById('textarea').value + keyChar;
}
</script>
Adam
Code One
05-17-2003, 10:27 PM
Exactly like this!
Good Job,
Code One
edit: Well not exactly. I just got threw messing with this code for about 2 hours trying to minipulate it to work as I need it to but I am rather new to Jscript and I have to admit my powers are limited, though according to my post this code would be exactly what I needed. Anyway . . .
What I need is for when the user presses a button lets say the (A) button on the users keyboard the output inside the textarea would be the number 10. Now I have a text box [on the same page] and I would like onKeyup the letter (A) to be outputed in the textbox minus the value which is set to be the number 10 vs. the actual value of the pressed button which is the letter (A).
I hope you understand and can help all is much appreciated,
Code One
P.s. 10 points to anyone who can decipher my quote.
AdamGundry
05-18-2003, 06:13 AM
I'm afraid I don't quite understand. Do you mean that when the user types a letter the ASCII value minus 10 should be outputted? Is the number 10 constant, or dependant on the letter? Can you explain a little more clearly, please.
Adam
P.S. Revolutionary
Charles
05-18-2003, 06:50 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
<!--
String.code = {a:26, b:25, c:24, d:23, e:22, f:21, g:20, h:19, i:18, j:17, k:16, l:15, m:14, n:13, o:12, p:11, q:10, r:9, s:8, t:7, u:6, v:5, w:4, x:3, y:2, z:1}
String.prototype.toCode = function () {
var a = this.split('');
for (j=0; j<a.length; j++) {if (String.code[a[j]]) a[j] = String.code[a[j]]}
return a.join('');
}
// -->
</script>
<form action="">
<div>
<p><label>Characters<br>
<textarea name="chars" rows="5" cols="20" onkeyup="this.form.codes.value = this.value.toCode()"></textarea></label></p>
<p><label>Codes<br>
<textarea name="codes" rows="5" cols="20" readonly></textarea></label></p>
</div>
</form>
Code One
05-18-2003, 02:17 PM
please observe the work of a genius above for my question threw him has been answered!!!
Great Job, nice pic!
Code One
P.s. 10 points goes to Adam for the deciphering my qoute!!
:)