Reputation: 131
I was working on something recently and I was struggling to get the result of A and place into B's box. Now I want to replace everything that says /test/ and replace it with 'banana'. But so far I haven't been able to get this to work. Can somebody explain where I am going wrong?
Javascript
<script>
function sync()
{
var A = document.getElementById('A');
var B = document.getElementById('B');
A = someString.replace(/test/, 'banana');
B.value = A.value;
}
</script>
Upvotes: 1
Views: 27
Reputation: 27
i would say to try:
var pattern = /test/;
A.value = someString.replace(pattern, 'banana');
Upvotes: -2
Reputation: 12391
Initially A and B both are objects, in the third line of the function, you are actually assigning string value to A, so you will have to use A instead of A.value
A = someString.replace(/test/, 'banana');
B.value =A; // because A has string value now
In order to make your code work, do this
A.value = someString.replace(/test/, 'banana');
Upvotes: 3