When trying to debug what is being submitted, I wrote this.
<form action="javascript:alert(this);"
I got object in alert box & unable to decide anything out of it. :-)
form action javascript. In an HTML form, the action attribute is used to indicate where the form's data is sent to when it is submitted. The value of this can be set when the form is created, but at times you might want to set it dynamically.
The JavaScript alert() function is a function available on the global window object. It commands the browser to display a modal dialog with a message and an "OK" button.
An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.
The HTML form action attribute defines where to send the form data when a form is submitted in an HTML document.
In your example this
is the global window
object. Try it yourself:
<form action="javascript:alert(typeof this.setTimeout);">
results in "function"
(i.e. the global function). Or try:
<form action="javascript:alert(this.nodeType);">
results in undefined
(i.e. it's not pointing to the form element)*.
The value of "this"
inside an attribute will only ever be one of two things:
window
objectThe only time this
points to the element itself is when it is used inside an intrinsic event attribute (the ones that are prefixed with "on"
, eg "onclick"
, "onload"
, etc). These attributes are special: the browser re-scopes this
to the element the event is firing on, and creates the event
object (with that name) also available inside the attribute.
If the attribute is not one of the intrinsic events, "this"
will be the global window
object.
Footnotes:
* unless of course you happened to have a global var named "nodeType"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With