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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking on parent page field on multi use form

Status
Not open for further replies.

stevehowe

Technical User
Mar 20, 2007
3
AU
I have a form which can be called as a subform from a parent form, or as a stand alone form straight from the opening menu.

If the form is called from a parent form I have to populate a radio button field. I have tried inheriting a field from the parent form but for some reason this doesn't want to work, possibly due to buggy application software, so this is not an option.

The solution I came up with involves calling a Javascript function when the page opens which works and populates the field:

function pop_how()
{
if (opener.MainForm.Field9999999_2025!=null){
MainForm.Field9992075_5578[2].checked=true;
}
}

This works a treat and allows me to default the field when opened from the parent form.

The problem comes when the form is opened standalone and opener.MainForm is null. How can I fix my function to take this into account?

I have tried changing the test to opener.MainForm!=null and get an error returned that opener.MainForm is not an object.
 
Check if [tt]opener[/tt] is not null, then check if [tt]opener.MainForm[/tt] is not null.
Code:
if(opener != null && opener.MainForm != null)

Or, for complete peace of mind, add in a final check for [tt]opener.MainForm.Field9999999_2025[/tt] and also a check to see if it has an option at array position 2:
Code:
if(opener != null && 
   opener.MainForm != null &&
   opener.MainForm.Field9999999_2025 != null &&
   opener.MainForm.Field9999999_2025[2] != null)

Javascript fails out of the logical test on the first [tt]false[/tt] it finds so you don't need to nest the [tt]if[/tt] statements, if anything leading up to the radio button you want to test is null it will stop looking and avoid the error.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top