JavaScript Runtime Error ( Undefined is null or not an object )
Well Alexia,
There is a small error on your code. The parameter you pass into the functions is undefined.
You can check that if you put an alert in each function like as below.
function Update(thisform) {
if (confirm("Are you sure you want to Update this reservation?"))
alert(thisform);
}
You can see that alert is returning an undefined message for thisform object.
You cannot pass the parameter as this.form to functions. It doesn’t mean anything when you use in the form tag itself.
<form action="/exhibitorhousing/housing-create.asp" method="post" onSubmit=Create(this.form); return false">
There is no object exist as this.form. You have to use the word ‘this’ to pass the form object into each functions like as below.
<form action="/exhibitorhousing/housing-create.asp" method="post" onSubmit=Create(this); return false">
I think you have a misunderstanding of accessing form objects.
If you use
<input type=submit value="Update" onclick="Update(this.form)">
Then there is some meaning because you use it in the input tag.
In the code above, the Update function call on onClick event handler of the form input button is being passed as this.form. Here this refers to the input object, and this.form references the form object. You can now make use of this form object in the Update function and access the form and all its elements.
Each and every element in a form tag triggers events, based on user action, which can be handled by a proper event handler. For example, the submit button being clicked triggers the onClick event handler. The 'this' keyword in JavaScript language always position to the object that calls a given method. The onClick event handler can be passed ‘this’ self-reference to get hold of a reference to the button element object.
Furthermore, in JavaScript language, every element object in a form tag has a property that references to the form object. So, if we pass this.form to the onClick event handler of a form button, this function gets the reference to the form object. This is a straightforward way to access form objects, because the form’s name or id attribute are never directly used. This is the basic option to use even there are multiple forms on a web page.
So I corrected your code and you can use it now. Cheers! It is 100% working code.
<!– Form elements 1st way –>
<form action="/exhibitorhousing/housing-delete.asp" method="post" onSubmit="Delete(this); return false">
<input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>">
<input type=hidden name="MODE" value="DELETE">
<input type=submit value="Delete">
</form>
<form action="/exhibitorhousing/housing-create.asp" method="post" onSubmit=”Create(this); return false">
<input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>">
<input type=hidden name="MODE" value="CREATE">
<input type=submit value="Create">
</form>
<form action="/exhibitorhousing/housing-update.asp" method="post" onSubmit="Update(this); return false">
<input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>">
<input type=hidden name="MODE" value="UPDATE">
<input type=submit value="Update">
</form>
Or else you can use it as
<!– Form elements 2nd way –>
<form action="/exhibitorhousing/housing-delete.asp" method="post" >
<input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>">
<input type=hidden name="MODE" value="DELETE">
<input type=submit value="Delete" onclick="Delete(this.form)">
</form>
<form action="/exhibitorhousing/housing-create.asp" method="post>
<input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>">
<input type=hidden name="MODE" value="CREATE">
<input type=submit value="Create" onclick="Delete(this.form)">
</form>
<form action="/exhibitorhousing/housing-update.asp" method="post" >
<input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>">
<input type=hidden name="MODE" value="UPDATE">
<input type=submit value="Update" onclick="Update(this.form)">
</form>