Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need variable in function to choose textfield on other page 1

Status
Not open for further replies.

realityshop

Instructor
May 8, 2001
3
US
I have a "registration form page" with numerous text fields,(i work at a school). These fields need "cycle numbers" sent to them via a "cycles page".

The first page, "reg form" opens a popup window with "cycles page" in it. "Cycles page" has buttons with the cycle numbers on them. This same page also has a function with two parameters. One param represents the cycle number to be sent to the reg form. The other param represents the actual Textfield on the reg form that should receive the cycle number. The second param will not work.
On this and other similar functions I get this error;

A runtime error has occured. line 16: bigForm.theCycle is null or not an object.

The first param (with the cycle number) works when i adjust the function to leave out the second param. The second param (naming the desired text field) will not work. The function will send only if i name the field literally, without use of the variable (which i need to do). If I replace theCycle with an actual field name like "t1cycle" -then all is well! Thanks anyone...the function is only 4 lines but i notated efforts as clues. oh boy...

var smallForm;
var bigForm;
var theValue;
var theBox;


function sendHome(theValue, theBox)
{
bigForm = window.opener.document.graphicsform;
smallForm = window.document.form1;
bigForm.theBox.value = theValue;

//WORKS: bigForm.t1cycle.value = theValue;
//WORKS: alert(theBox);
//WORKS: alert(bigForm.name);
//WORKS: alert(window.opener.document.forms[0].name);
/*NOT WORKING: window.opener.document.graphicsform.theBox.value = theValue;*/
//WORKS: alert(smallForm.CGT11M.value);
//WORKS: alert(theBox);
}

and the button...
<input type=&quot;button&quot; name=&quot;CGT11M&quot; value=&quot;CGT1-1M&quot; onclick = &quot;return sendHome('CGT11M', 't1cycle')&quot;>
 
send the
Code:
theBox
as a string (I.E. &quot;t1cycle&quot;)
then have an eval method in your function like this.

function sendHome(theValue, theBox)
{
bigForm = window.opener.document.graphicsform;
smallForm = window.document.form1;
eval(&quot;bigForm.&quot; + theBox + &quot;.value = &quot; + theValue);
// or eval(&quot;window.opener.document.graphicsform.&quot; + theBox + &quot;.value = &quot; + theValue);
}

Hope this helps. Klae

You're only as good as your last answer!
 
Thanks Klae! I think I see. But it still is not working. Now it seems theValue isn't recognized. My button assigns it a value of 'CGT11M'. But I get an error that 'CGT11M' is undefined. Strangely, this variable worked before I introduced the eval statement. Could you tell me what I'm missing? Thanks so much for you generous help!!!
Below is your last response followed by the code in my button.

You said:
send the theBox as a string (I.E. &quot;t1cycle&quot;)
then have an eval method in your function like this.

function sendHome(theValue, theBox)
{
bigForm = window.opener.document.graphicsform;
smallForm = window.document.form1;
eval(&quot;bigForm.&quot; + theBox + &quot;.value = &quot; + theValue);
// or eval(&quot;window.opener.document.graphicsform.&quot; + theBox + &quot;.value = &quot; + theValue);
}
The Button's code:
<input type=&quot;button&quot; name=&quot;CGT11M&quot; value=&quot;CGT1-1M&quot; onclick = &quot;return sendHome('CGT11M', 't1cycle')&quot;>

 
I got it! If I put theValue in quotes, just like &quot;bigForm.&quot;, then it works. I better get hip to EVAL! Special thanks to Klae, I really appreciate it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top