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

How to determine the parent form

Status
Not open for further replies.

esac

Programmer
Nov 22, 2000
3
US
I am trying to determine which form in my webpage an object belongs to after passing its full location into the function.

In the following example I pass wc.wcUser to the function and alert if it belongs to wcForm (or at least thats what I want to do)

So if I call wcIsNull(document.wcForm.wcUser,'bleh'); I can tell that the parent form is document.wcForm .. that way I can pass information from other forms into the function and not have that part processed.

If you need any more explanation just ask, I find it hard to explain exactly what I am trying to do here :)


<SCRIPT LANGUAGE=&quot;Javascript&quot;>
function wcIsNull(itmForm,msgAlert) {
if (itmForm.value == '') {
alert(msgAlert);
alert((itmForm.??????? == document.wcForm) ? 'it is' : 'it is not');
itmForm.focus();
}
}
</SCRIPT>

<form name=&quot;wcForm&quot; onsubmit=&quot;wc = document.wcForm; wcIsNull(wc.wcUser,'Please enter a username.'); return false&quot;>
<input type=&quot;text&quot; name=&quot;wcUser&quot; value=&quot;&quot;>
<input type=&quot;submit&quot;>
</form>
 
?? what you want to know is if wcUser is in wcForm ???

return(wcForm.wcUSer) [---> true if it is, false else]

 
Yes, but see how I pass it to the function, essentially I pass document.wcForm.wcUser to the function. It doesn't matter what object I pass to it, I want to determine which form it came from.. better example, essentially what I am trying to figure out is the stuff in skeleton code:

<SCRIPT LANGUAGE=&quot;Javascript&quot;>
function fIsNull(itmForm) {
if (itmForm.value == '')
if ('itmForm's parent form' == document.wcForm) {
Update some stuff in document.wcForm
} else {
Update some stuff in document.quForm
}

itmForm.focus();
return true;
}
return false;
}

function SubmitHandler() {
if (fIsNull(document.wcForm.wcUser) ||
fIsNull(document.quForm.quBleh) {
return false;
}
}

</SCRIPT>

<form action=&quot;handleit.asp&quot; method=&quot;POST&quot; onSubmit=&quot;return SubmitHandler();&quot; NAME=&quot;wcForm&quot;>
<input type=text name=wcUser>
<input type=submit>
</form>

<form action=&quot;handlequ.asp&quot; method=&quot;POST&quot; onSubmit=&quot;return SubmitHandler();&quot; NAME=&quot;quForm&quot;>
<input type=text name=quBleh>
<input type=submit>
</form>
 
i would have done that the other way : instead of looking for the parent's form (coz i don't know how to do this either !) i would have compared itmform to the CHILDREN of wcform :
function is_the_form_in_wcform(ItmForm) {
for (var m=0; m<document.wcForm.forms.length; m++) {
if (document.wcForm.forms[m]== itmForm)
return true
} // close for
return false;
}

another solution is that it seems you have only 2 possible parents form, so compare one after the other :
if (document.wcform.itmform)
// do whatever you were supposed to do if Itm is a child of wcform
elseif (document.quform.itmform)
// do whatever you were supposed to do if Itm is a child of quform
else
//something went wrong !! it's on none of the parents frames !

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top