Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

function copy not working for me

Posted on 2009-05-01
4
Medium Priority
?
160 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:jackie777
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:bugada
ID: 24278786
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
 

Author Comment

by:jackie777
ID: 24278971
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
 
LVL 10

Accepted Solution

by:
bugada earned 2000 total points
ID: 24279014
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
 

Author Closing Comment

by:jackie777
ID: 31576857
Sorry, I was doing something else wrong, it did work after all. Thanks for your help.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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