?
Solved

Microsoft JScript runtime error: 'form.elements' is null or not an object  runtime error while

Posted on 2010-01-07
4
Medium Priority
?
869 Views
Last Modified: 2012-08-14
I have an asp page which submits the form to another page. I call a javacript function to check the fields before submitting.

I get the following error in IE when i submit the form.
The date field is a textbox which takes input from a calender control.
 Code is below. please suggest.


Thanks
function checkForm(elem)
{
	if(elem.form.elements['pubdate'].value =='' )
	{
		alert('Please specify the end date');
		elem.form.elements['pubdate'].focus();
		return false;
	}

return true;
}


----------------------------

this is my form post..
<form method="post" action="MAction.asp" onsubmit="return checkForm(this);">

i have a save button which has an onclick check as below, though i removed the onclick parameters the error occurs.

<input type="submit" value="Save" onclick="return checkForm(this);" name="Submit1">

Open in new window

0
Comment
Question by:nirisan
  • 2
4 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26202748
Hello nirisan,

Assuming you pass the form itself as object to checkForm you don't need to add form again :


function checkForm(elem)
{
        if(elem.elements['pubdate'].value =='' )
        {
                alert('Please specify the end date');
                elem.elements['pubdate'].focus();
                return false;
        }

return true;
}


----------------------------

this is my form post..
<form method="post" action="MAction.asp" onsubmit="return checkForm(this);">

i have a save button which has an onclick check as below, though i removed the onclick parameters the error occurs.

<input type="submit" value="Save" onclick="return checkForm(this);" name="Submit1">

Open in new window

0
 

Author Comment

by:nirisan
ID: 26203250
Hi leakim971,

I have removed the form as you suggested. But i still get this error. Please advise.

Microsoft JScript runtime error: 'elements.pubdate' is null or not an object
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26203472
Could you post your entire page ?
0
 
LVL 22

Accepted Solution

by:
kadaba earned 2000 total points
ID: 26203794
It will work if you have a pattern similar to the attached code...
If its a server side control the client side id name might differ than whats provided.

hence you might be getting the error.
paste the html code from the browser.

<html>
<head>
<title>form validation</title>
<script type="text/javascript">
function checkForm(elem)
{
	if(elem.elements['pubdate'].value =='' )
	{
		alert('Please specify the end date');
		elem.elements['pubdate'].focus();
		return false;
	}
	return true;
}

</script>
</head>
<body>
<form action="http://www.google.com" onsubmit="return checkForm(this);">
	Date :<input type="text" id="pubdate" name="pubdate">
	<br>
	<input type="submit" name="mySubmit" value="Submit">
</form>
</body>
</html>

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question