0
<script type="text/javascript">
    function parent_work_copy(track_number) {    
      document.form1.track_(track_number)_name.value=document.form1.track_(track_number)_parent_work.value;
   }
</script>

If the link below is clicked, I want the line inside of the parent_work_copy function to be modified to:

document.form1.track_5_name.value=document.form1.track_5_parent_work.value
<a href="javascript:parent_work_copy(5)">copy to track</a>

How to do this?

deceze
  • 510,633
  • 85
  • 743
  • 889
  • 2
    No, you do not want to modify source code on the fly. Wrong approach. You want to write code which can take a variable and act accordingly, without modifying itself. – deceze Oct 04 '16 at 09:32
  • Variables are your friends, they'll store data for you. Try `var`. – zer00ne Oct 04 '16 at 09:35

2 Answers2

0

Do something like this :

document.form1['track_'+track_number+'_name'].value

Steeve Pitis
  • 4,283
  • 1
  • 21
  • 24
0

Javascript object keys works as string

 document.form1["track_"+track_number+"_name"].value=document.form1["track_"+track_number+"_parent_work"].value;
Daphoque
  • 4,421
  • 1
  • 20
  • 31