function copy not working for me

Posted on 2009-05-01
Last Modified: 2012-05-06

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 =;

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 =;

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

Question by:jackie777
    LVL 10

    Expert Comment

    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 =;
    d = d.substring(3);
    d = "L_DESC" + d;
    obj2.form[d].value = obj2.value;

    Open in new window


    Author Comment

    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?
    LVL 10

    Accepted Solution

    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.

    Author Closing Comment

    Sorry, I was doing something else wrong, it did work after all. Thanks for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    This article will show, step by step, how to integrate R code into a R Sweave document
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    The viewer will learn how to count occurrences of each item in an array.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now