PDA

View Full Version : textboxes



a++
10-09-2008, 09:54 PM
How could I take text from one textbox and put it into another textbox? Can anyone tell me how to do this by pressing a button?

Thank you in advance.

===

The distant cousin of c++,
a++

magicyte
10-09-2008, 09:57 PM
Heh, whoa!! Taking text from one text box and putting it into another text box? Here is some code:


<html>
<head>
<script type="text/javascript">
function add(t,u)
{
document.getElementById(u).value = document.getElementById(t).value;
}
</script>
</head>
<body>
<input type="text" id="t1"><br /><input type="text" id="t2"><br /><input type="button" value="Add" onclick="add('t1','t2');">
</body>
</html>

a++
10-09-2008, 09:59 PM
Oh, wow! Thanks for that quick reply! It works great!

Much thanks!

===

The distant cousin of c++,
a++

magicyte
10-09-2008, 10:00 PM
Ah. Don't mention it. :)

-magicyte

Twey
10-09-2008, 10:34 PM
Here is some better code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Page Sans Titre</title>
</head>
<body>
<form action="/server/side/equivalent"
onsubmit="return (this.elements.text1.value = this.elements.text2.value), false;">
<div>
<textarea name="text1">Foo</textarea>
<textarea name="text2">Bar</textarea>
<input type="submit" value="Copy">
</div>
</form>
</body>
</html>magicyte, never forget your validation, and stay away from the pseudo-XHTML and presentational markup.

a++
10-10-2008, 12:30 AM
Thanks for the code, Twey!!

===

The distant cousin of c++,
a++