admin管理员组

文章数量:1024582

I know this can be acplished by Javascript, and I am learning so please tell me, when I click an update button I want the text from a textbox to be copied into another one.

I know this can be acplished by Javascript, and I am learning so please tell me, when I click an update button I want the text from a textbox to be copied into another one.

Share Improve this question asked Apr 2, 2011 at 18:47 TotallyPwnageTotallyPwnage 531 gold badge1 silver badge6 bronze badges 1
  • can you please post what you have so far in terms of code? – KJYe.Name Commented Apr 2, 2011 at 20:32
Add a ment  | 

4 Answers 4

Reset to default 1

Assuming you have this:

<textarea id="source"></textarea>
...
<textarea id="target"></textarea>
...
<button type="button" onclick="update();">Update</button>

Then your JS function can be:

function update() {
    document.getElementById('target').value = document.getElementById('source').value;
}
jQuery solution - check it out (jQuery that is)
$('#button').click(function(e) {
  e.preventDefault();
  $('#totextarea').val($('#fromtextarea').val());
  ...then submit the form if you wish to or whatever...
  $('#theform').submit();
});

Try the following

<script>
function onSubmitClick() {
  var box1 = document.getElementById('box1');
  var box2 = document.getElementById('box2'); 
  box2.value = box1.value;
}
</script>

<textarea id='box1'></textarea>
<textarea id='box2'></textarea>
<button onclick='onSubmitClick(); return false'>Click Me</button>

JSFiddle Demo

  • http://jsfiddle/Wr8L8/
<script>
function sync()
{
  // Take first and second value by element ID
  var n1 = document.getElementById('n1');
  var n2 = document.getElementById('n2');
  // Assign the value of the 1st to the 2nd text box
  n2.value = n1.value;
}
</script>

<input type="text" name="n1" id="n1" />
<input type="text" name="n2" id="n2"/>
<!-- you put a function sync to be executed on click on the button --> 
<button onclick="sync()">Synchronize</button>

I know this can be acplished by Javascript, and I am learning so please tell me, when I click an update button I want the text from a textbox to be copied into another one.

I know this can be acplished by Javascript, and I am learning so please tell me, when I click an update button I want the text from a textbox to be copied into another one.

Share Improve this question asked Apr 2, 2011 at 18:47 TotallyPwnageTotallyPwnage 531 gold badge1 silver badge6 bronze badges 1
  • can you please post what you have so far in terms of code? – KJYe.Name Commented Apr 2, 2011 at 20:32
Add a ment  | 

4 Answers 4

Reset to default 1

Assuming you have this:

<textarea id="source"></textarea>
...
<textarea id="target"></textarea>
...
<button type="button" onclick="update();">Update</button>

Then your JS function can be:

function update() {
    document.getElementById('target').value = document.getElementById('source').value;
}
jQuery solution - check it out (jQuery that is)
$('#button').click(function(e) {
  e.preventDefault();
  $('#totextarea').val($('#fromtextarea').val());
  ...then submit the form if you wish to or whatever...
  $('#theform').submit();
});

Try the following

<script>
function onSubmitClick() {
  var box1 = document.getElementById('box1');
  var box2 = document.getElementById('box2'); 
  box2.value = box1.value;
}
</script>

<textarea id='box1'></textarea>
<textarea id='box2'></textarea>
<button onclick='onSubmitClick(); return false'>Click Me</button>

JSFiddle Demo

  • http://jsfiddle/Wr8L8/
<script>
function sync()
{
  // Take first and second value by element ID
  var n1 = document.getElementById('n1');
  var n2 = document.getElementById('n2');
  // Assign the value of the 1st to the 2nd text box
  n2.value = n1.value;
}
</script>

<input type="text" name="n1" id="n1" />
<input type="text" name="n2" id="n2"/>
<!-- you put a function sync to be executed on click on the button --> 
<button onclick="sync()">Synchronize</button>

本文标签: javascriptCopy value from one textbox to another using submit buttonStack Overflow