function copy not working for me

Hi,

I have a function that takes data inputed into a form field and copies it over to a hidden form field.
The function works with a series of variables named L_QTY0, L_QTY1, L_QTY2 ect.

It is called in the first form field using: copyValue(this)

This all worked very well, however now I have a second set of variables that I need to have this function applied to and it isn't working for me and I don't understand why. I made a new function based on the first one as to not effect the first one at all. The second version of the function and the new call code are listed below as well as the first.


I have been trying unsuc


<!-- first working Javascript function -->
function copyValue(obj)
{
n = obj.name;
n = n.substring(4,n.indexOf("_"));
n = "L_QTY" + n;
 
obj.form[n].value = obj.value;
 
}
 
<!-- first working Javascript call  copyValue(this)-->
 
 <input type="text" name="item0_qty" size="4" value="0" tabindex="1" onchange="getProductTotal(this,this.form);copyValue(this)" onclick="checkValue(this)" onblur="reCheckValue(this)" />
 
<!-- second not-working Javascript function -->
 
function copyValue2(obj2)
{
d = obj2.name;
d = d.substring(4,d.indexOf("_"));
d = "L_DESC" + d;
 
obj2.form[d].value = obj2.value;
 
}
 
<!-- second not-working Javascript call  copyValue(this)-->
 
<textarea name="msg0" id="msg0" cols="15" rows="5" value="" onchange="copyValue2(this)"></textarea>

Open in new window

jackie777Asked:
Who is Participating?
 
bugadaConnect With a Mentor Commented:
well it should work.

But you can change the name of textarea in this way: item0_msg
in this way your original function should work.
0
 
bugadaCommented:
your functions copValue and copValue2 uses the name of the element to extract the id.
In the first case the name is "item0_qty" and the value extracted is "0" (the chars between the fourth char and the underscore).

In the second case you do he same, but your textarea name is not fllowing this rule. I think you should modify the second function like this:
function copyValue2(obj2)
{
d = obj2.name;
d = d.substring(3);
d = "L_DESC" + d;
 
obj2.form[d].value = obj2.value;
 
}

Open in new window

0
 
jackie777Author Commented:
Thanks for the explanation, I now understand this function a bit better.

Your function didn't work for me thought. It actually disables a few other functions on my page. But when i put a 4 in place of the 3 the other functions on my page started working properly again.

It still didn't work with the 4 either. Any other ideas?
0
 
jackie777Author Commented:
Sorry, I was doing something else wrong, it did work after all. Thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.