admin管理员组文章数量:1200974
I have two forms.
I want to copy the value of one of the text fields in form 1 into another in form 2.
Text field names and ids are different.
How can I achieve this?
This didn't work:
document.getElementById('name').value = document.getElementById('user').value;
Thanks!
I have two forms.
I want to copy the value of one of the text fields in form 1 into another in form 2.
Text field names and ids are different.
How can I achieve this?
This didn't work:
document.getElementById('name').value = document.getElementById('user').value;
Thanks!
Share Improve this question asked Feb 25, 2013 at 16:10 Claudio DelgadoClaudio Delgado 2,3497 gold badges21 silver badges27 bronze badges 2- 1 Are you using jQuery or not - because thats vanilla js youve posted in your question? – prodigitalson Commented Feb 25, 2013 at 16:12
- Check for duplicate ID, that is invalid and would have the potential to make the above fail. – Mark Schultheiss Commented Feb 25, 2013 at 16:16
3 Answers
Reset to default 17If you're asking for jQuery you could try:
$("#name").val($("#user").val());
http://jsbin.com/exudif/2/
$(document).ready(function()
{
$('#btn1').click(function()
{
$('#field2').val($('#field1').val());
});
});
To get the value using jquery .it has to be done this way . Also make sure you have given id to the input fields .
like this: <input type='text' name='user' id='user' >
Then only this code will work properly
$(document).ready(function()
{
$('#buttonElement').click(function()
{
$('#name').val($('#user').val());
});
});
本文标签:
版权声明:本文标题:javascript - jQuery Copy text field's value from a different form into another form's text field - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738623611a2103336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论