Passing field name to the function

Results 1 to 3 of 3

Thread: Passing field name to the function

  1. #1
    Elaine Guest

    Default Passing field name to the function

    I have a form with aset of text boxes. Beside each text box there is link which pops up a new window. The user may select a name from the new window and the textbox in the parent window is populated by that field. Now I want to make the pop up window generic so that when I click on any link for the pop up window, it should populate the corresponding text bax. For this I need to pass in the name of the text box in the function that populates the text box in the parent window.<BR><BR><BR>I tried using this, But doesn&#039t work. Can anybody help me??<BR><BR>function DoMakeSelection(fld) {<BR>//where fld is &#039NOMINATIONS.txtname0&#039 (ie Form Name.fld name)<BR>e = &#039opener.document.&#039 + fld + &#039.value&#039<BR>//asign the value of the selection box to the text box in the main window.<BR>e = document.form1.selection_list.options[document.form1.selection_list.selectedIndex].text;<BR>self.close()<BR>}<BR><BR>Where am I going wrong??<BR><BR>Thanks,<BR><BR>Elaine<BR><BR><BR>

  2. #2
    Matt Jacyno Guest

    Default RE: Passing field name to the function

    Elaine,<BR>I can see where you&#039re having trouble. In your function you were trying to do two things that sound right:<BR>1) Make e be a reference to a text field value<BR>2) Simply set that value<BR><BR>But what is really happening is:<BR>1) e actually contains the string "opener.document.(fieldname here).value" - it&#039s not a reference to the form field<BR>2) e then gets set to the value of the select list<BR><BR>Which isn&#039t what you want.<BR><BR>Try something like this<BR><BR>function DoMakeSelection(fld) {<BR><BR>// below is all one line of code<BR>eval(&#039opener.document.&#039 + fld + &#039.value&#039) = document.form1.selection_list.options[document.form1.selection_list.selectedIndex].text;<BR><BR>self.close()<BR>}<BR><BR><BR>Haven&# 039t tested that, but give it a try. Javascript&#039s eval() method allows you to treat the arguments as an actual expression or object (in this case, a form value) instead of a text string.<BR><BR>Give it a try, and let me know if that works ok,<BR>Matt<BR>

  3. #3
    Elaine Guest

    Default RE: Passing field name to the function

    Thanks Matt for the prompt reply. But I am getting an error that reads : Cannot assign to a function result.<BR><BR>But you have understood my problem Can you suggest a workaround or maybe even suggest something??<BR><BR>Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts