PDA

View Full Version : Putting textbox text into variable



Penny94
10-14-2012, 11:49 PM
How do I get the text from a textbox into a variable?

I am trying to make it so onclick text from one textbox is put into another:


<script type="text/javascript">
var test= ???
function movetext(){
document.getElementById("text2").value=test;
}
</script>

<a onclick="movetext(); return false;">Click</a>

<input type="text" id="text1"><br><br>
<input type="text" id="text2">

Thanks for your help

jscheuer1
10-15-2012, 01:13 AM
To copy:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function movetext(){
document.getElementById("text2").value = document.getElementById("text1").value;
}
</script>

</head>
<body>
<a href="#" onclick="movetext(); return false;">Click</a>

<input type="text" id="text1"><br><br>
<input type="text" id="text2">

</body>
</html>

To move:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function movetext(){
document.getElementById("text2").value = document.getElementById("text1").value;
document.getElementById("text1").value = ''
}
</script>

</head>
<body>
<a href="#" onclick="movetext(); return false;">Click</a>

<input type="text" id="text1"><br><br>
<input type="text" id="text2">

</body>
</html>