We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

JavaScript err 'is null or not an object"

UPRRDevelopers
on
Medium Priority
993 Views
Last Modified: 2012-06-21
I'm trying to validate a form to verify that the user selects at least one checkbox.  I have seen several examples on the web, and I thought mine should mimic those pages, but instead I continually receive error  'document.rtaform.region.0' is null or not an object' every time I try.  This is part of the code.  Please point me in the right direction.  Thanks!
<script>
function checkBoxes()
{
	if (document.rtaform.region[0].checked == false)
	{
	if (document.rtaform.region[1].checked == false)
	{
	if (document.rtaform.region[2].checked == false)
	{
	alert('Please Select a Region');
	return false;
}
}
	return true;
}
 
function verifyChecked()
{
	if (!checkBoxes()) return false;
	document.rta.submit();
	return true;
}
 
</SCRIPT>
 
<form name ="rtaform" action="rtatickets.cfm?bdate=#bdate#&btime=#btime#&edate=#edate#&etime=#etime#&ticketstatus=#ticketstatus#" method = "get">
 
	<div class="ricGroupbox" ric:title="Entry Date and Time Info" ric:width = 600>
		<table width="600" height="82"><br>
	  <STRONG>Be sure to use DD-MON-YY format for Dates and HH:MM:SS format for Times</STRONG> <br>
	  <br>
		<tr>
			<td width="150"><label class="ricRequired">Begin Date: </label></td>
		  	<td width="125"><input type="text" size=15 name= "bdate" <cfoutput> value=#todaysdate# </cfoutput> onBlur="bdate.toUppercase" class="ricDefaultText"/></td>
			  <td width="200"><label class="ricRequired">Time (Optional):</label></td>
			  <td width="200"><input type="text" name= "btime" size=15 value="00:00:00" class="ricDefaultText"/></td>
			</tr>
			<tr>
	     	  <td width="105"><label class="ricRequired">End Date: </label></td>
		     <td width="154"><input type="text" size=15 name= "edate" <cfoutput> value=#todaysdate# </cfoutput> onBlur="edate.toUppercase" class="ricDefaultText"/></td>
			 <td width="200"><label class="ricRequired">Time (Optional):</label></td>
			 <td width="200"><input type="text" name= "etime" size=15 value="23:59:59" class="ricDefaultText"/></td>
		</tr>
	  </table>
	</div>  <!-- Date and Time Section END -->
 
	<div class="ricGroupbox" ric:title="Region Selection" ric:width = 600>
		<table width="700" height="20">
			<tr>
			<td width="125"><label>Northern</label></td>
			<td width="150"><input type="checkbox" name= "region" value = "Northern" checked class="ricDefaultText"/></td>
			</tr>
			<tr>
			<td width="125"><label>Southern</label></td>
			<td width="150"><input type="checkbox" name= "region" value = "Southern" checked class="ricDefaultText"/></td>
			</tr>
			<tr>
			<td width="200"><label>Western</label></td>
			<td width="150"><input type="checkbox" name= "region" value = "Western" checked class="ricDefaultText"/></td>
			</tr>
	  </table>
	</div>  <!-- Region Selection END -->
 
 
	  <br><br>
 
      <input type="submit" value="Run Report" onClick="verifyChecked()">

Open in new window

Comment
Watch Question

Author

Commented:
Well I noticed that I have three opening IF brackets in the checkBoxes function but only two to close.  I added a third closing bracket, but that didn't fix the problem.
CERTIFIED EXPERT
Commented:
first thing
 
pleasechnage your submit to this
<input type="submit" value="Run Report" onClick=" return verifyChecked()">
add return
 
and then js function checkboxes change to this.
function checkBoxes()
{
 if (document.rtaform.region[0].checked == false)
 {
 if (document.rtaform.region[1].checked == false)
 {
 if (document.rtaform.region[2].checked == false)
 {
 alert('Please Select a Region');
 return false;
}
}
}
 return true;
}
 

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks... I made the changes, but I still get the error.  This is it exactly:

Line: 18 (which is the first line of the checkBoxes function after the bracket)
Char: 1
Error:  'document.rtaform.region.0' is null or not an object
Code:0

Author

Commented:
I found it ... I never closed the /FORM tag.  When I did that, everything worked fine.  Thanks for the help.
I think that this error is return because the tickbox is not checked ... then the javascript test something who don't exist.
Try to replace by :
if (document.rtaform.region[0] != null)

It will test if it exist, the tickbox is not send in the form if not "ticked"
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.