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

Is Null or Not an Object

Status
Not open for further replies.

awieland

Programmer
Apr 18, 2005
36
US
I am receiving the following JavaScript error:
'document.W4Form.Married' is null or not an object.

Here is my code:

<xsl:choose>
<xsl:when test="(MarriedFileSingle)='Y'">
<INPUT type="checkbox" name="fMarriedFileSingle" onClick="javascript:marriedSingle()" checked="yes"></INPUT>
</xsl:when>
<xsl:eek:therwise>
<INPUT type="checkbox" name="fMarriedFileSingle" onClick="javascript:marriedSingle()" ></INPUT>
</xsl:eek:therwise>
</xsl:choose>


<script LANGUAGE="JavaScript">

if (document.W4Form.fMarriedFileSingle.checked ==true) document.W4Form.MarriedFileSingle.value = "Y";
else document.W4Form.MarriedFileSingle.value = "N";

function marriedSingle() {
// set the hidden field for the MarriedFileSingle with Y/N for checked/unchecked event of the check box
if (document.W4Form.fMarriedFileSingle.checked ==true) document.W4Form.MarriedFileSingle.value = "Y";
else document.W4Form.MarriedFileSingle.value = "N";

}

</script>

Thank in Advance for your kind help.


 

Do you have a form declared anywhere? Do you have an element named "Married" anywhere?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Yes, I have a form declared:

<FORM action="W4Router" method="Post" name="W4Form">
</FORM>

I also have an update form declared after data is sent to the DB:

<FORM name="updateW4Form" action="W4Router?Funct_W4_UPDATE=Update">
<INPUT type="hidden" name="FilingStatus" value=" "/>
<INPUT type="hidden" name="MarriedFileSingle" value=" " />
<INPUT type="hidden" name="WithholdingType" value=" "/>
<INPUT type="hidden" name="TotalAllowances" value=" " />
<INPUT type="hidden" name="WithholdingAmount" value=" "/>
<INPUT type="hidden" name="Funct_W4_UPDATE" value="Update"/>
</FORM>
 
You still haven't answered Dan's question:
Do you have an element named "Married" anywhere?

Considering that this was the error: 'document.W4Form.Married' is null or not an object.

You still haven't shown us anywhere where Married is defined.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
[banghead]
 

But you have no element named "Married" in that form. Have you posted all your JavaScript code? Is there anywhere that you are trying to access an elements names "Married"?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I am very sorry but I mistyped my error message, it should say:

I am receiving the following JavaScript error:
'document.W4Form.MarriedFileSingle' is null or not an object.

NOT "Married" the elecment is "MarriedFileSingle".
 
From the incomplete code I've seen so far, I'm guessing that this:

Code:
document.W4Form.MarriedFileSingle

should be:

Code:
document.[b]update[/b]W4Form.MarriedFileSingle

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I already use the update code, see below:

function UpdateW4(){

document.updateW4Form.FilingStatus.value = filingStatus;
document.updateW4Form.MarriedFileSingle.value = document.W4Form.marriedSingle.value;
document.updateW4Form.TotalAllowances.value = document.W4Form.TotalAllowances.value;
document.updateW4Form.WithholdingType.value = document.W4Form.WithholdingType.value;
document.updateW4Form.WithholdingAmount.value = document.W4Form.WithholdingAmount.value;

document.updateW4Form.submit();
}
 

So, with the updated code, what is the error you are now getting, and at what point does it happen?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
The error appear as soon as the page is displayed and it says:

'document.W4From.MarriedFileSingle' is null or not an object
 
Aaah - you are probably trying to access the form element before the page has loaded. Put your form calls in a function, and call that onload with:

Code:
<body onload="yourFunctionName();">

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I thought I was already doing that with this function "marriedSingle()". If I am not can you be a little more specific, please?

function marriedSingle() {
// set the hidden field for the MarriedFileSingle with Y/N for checked/unchecked event of the check box
if (document.W4Form.fMarriedFileSingle.checked ==true) document.W4Form.MarriedFileSingle.value = "Y";
else document.W4Form.MarriedFileSingle.value = "N";

}
 
If I am not can you be a little more specific, please?

Happy to oblige. In your first post, you have this code:

Code:
<script LANGUAGE="JavaScript">

[b]if (document.W4Form.fMarriedFileSingle.checked ==true) document.W4Form.MarriedFileSingle.value = "Y";
else document.W4Form.MarriedFileSingle.value = "N";[/b]

function marriedSingle() {
        // set the hidden field for the MarriedFileSingle with Y/N for checked/unchecked event of the check box
if (document.W4Form.fMarriedFileSingle.checked ==true) document.W4Form.MarriedFileSingle.value = "Y";
else document.W4Form.MarriedFileSingle.value = "N";
        
}

</script>

Notice that the bold lines are not in a function, and so will be run as they are parsed.

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top