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
4 Answers
Reset to default 1Assuming 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
4 Answers
Reset to default 1Assuming 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
版权声明:本文标题:javascript - Copy value from one textbox to another using submit button - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745610943a2158999.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论