Hi all,
sorry for this simple problem, but I seem to not be able to see the wood for all of the trees...
the following is a simpler version of a script that I am working on and I am getting the error: this.form.name is undefined.
Obviously I do have a name and an id...
What's the matter???
<form id="form_2_update_for_72" name="form_2_update_for_72" method="POST">
<a onclick="alert(this.form.name)">show me this.form.name...</a>
</form>
<hr>
<form id="form_2_update_for_73" name="form_2_update_for_73" method="POST">
<a onclick="alert(this.form.name)">show me this.form.name...</a>
</form>
"this" refers to the object tasked to perform the event, here you are refering "this" to the link that performs the onclick event, thus trying to display the name of the links object, "form", which does not exist.
If you want to get the name of the form that the link is a child to, you could try climbing up the dom tree with something like alert(this.parentNode.name) or something, but this can give different results in different browsers.
Try telling us what you are trying to do with the code, why u need the name and when to get it, maybe it will be easier to figure out...
"this" refers to the object tasked to perform the event, here you are refering "this" to the link that performs the onclick event, thus trying to display the name of the links object, "form", which does not exist.
If you want to get the name of the form that the link is a child to, you could try climbing up the dom tree with something like alert(this.parentNode.name) or something, but this can give different results in different browsers.
Try telling us what you are trying to do with the code, why u need the name and when to get it, maybe it will be easier to figure out...
the form I am actually using is generated on the fly via php and a smarty template. The thing is that this particular function (a calendar field) works just fine in all the other modules and I was surprised that it doesn't work here, however I was able to get the same error message as from my actual form field...
Essentially I have got a set of fields that lead to a calendar control using javascript to call the respective functions and format the output.
I thought "this" usually points to the current form...probably have been mistaken :-/
Nevertheless how would I reference the actual form that contains my current field...?
the form I am actually using is generated on the fly via php and a smarty template. The thing is that this particular function (a calendar field) works just fine in all the other modules and I was surprised that it doesn't work here, however I was able to get the same error message as from my actual form field...
Essentially I have got a set of fields that lead to a calendar control using javascript to call the respective functions and format the output.
I thought "this" usually points to the current form...probably have been mistaken :-/
Nevertheless how would I reference the actual form that contains my current field...?
Hah, I figured it out...
The solution is instead of this.form
The answer is simple. A link is not one of the form's elements (controls). A form can have, as his controls, only: INPUT, TEXTAREA, SELECT, BUTTON and (with some crossbrowser differences) OBJECT elements.
Bookmarks