-
September 17th, 2005, 02:56 AM
#1
Javascript Error : Is Null or Not an Object
I have a javascript
function sortThis(thisform, sortval)
{
thisform.sort.value = sortval;
if(thisform.type.value == "ASC")
thisform.type.value = "DESC";
else
thisform.type.value = "ASC";
thisform.submit();
}
and 2 form elements and I have some hyper links where I say
<FORM>
<INPUT TYPE="hidden" Name="sort" VALUE="">
<INPUT TYPE="hidden" Name="type" VALUE="">
<A HREF="#" onClick="sortThis(this.form, 'PERSONS.last_name, PERSONS.first_name')">Name</A>
</FORM>
when I click this hyperlink I get a error message that sort is null or not an object! is there something wrong I am doing? When I use a button, this works fine but when done through a hyper link its not working. Any ideas?
-
September 17th, 2005, 07:04 AM
#2
Re: Javascript Error : Is Null or Not an Object
The reason is because of the types of tags you are using. A button has a form property that references the form object, .form. Contrarily, a hyperlink doesn't have this property. You could use this.parentNode instead, which refers to the node one level up.
*9-11-01* Never Forget; Never Forgive; Never Relent!
"If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan
-
September 17th, 2005, 10:04 AM
#3
Re: Javascript Error : Is Null or Not an Object
and how do I use the this.parentNode ?
-
September 17th, 2005, 12:03 PM
#4
Re: Javascript Error : Is Null or Not an Object
The two following changes are needed:
Code:
...
<FORM name="my_form">
...
<A HREF="#" onClick="sortThis(document.my_form, 'PERSONS.last_name, PERSONS.first_name')">Name</A>
-
September 17th, 2005, 09:24 PM
#5
Re: Javascript Error : Is Null or Not an Object
This solution will work ... but if you move it to a different form, it still references the same form. To use .parentNode, use this example to see its use:
Code:
<form name="myForm">
<a href=#" onclick="javascript:alert(this.parentNode.name)">Test</a>
<!-- alerts myForm onclick -->
</form>
So really, replace this.form as your first argument with this.parentNode, and voila! Unless of course, you have the <a> inside a fieldset or div or something, but that isn't shown in your code.
*9-11-01* Never Forget; Never Forgive; Never Relent!
"If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|