I have a form marked as
<form class="form1" method="post" action="form1.php" style="width:405px">
Usually I could access the form action in javascript by accessing the .action of the form object, e.g.
document.forms[0].action
which will return the value
form1.php
However, if I have an element named "action" as a component of the form, this "action" becomes the content of the form action. That is, if the markup of the form contains, for example,
<input name="action" type="hidden" value="check" />
Then
document.forms[0].action
returns value
<input name="action" type="hidden" value="check" />
Now I figured out how to get around this: using
document.forms[0].getAttribute("action")
However, this is an unpleasant gotcha that too embarrassed me. This is mistake? Known DOM management issue? Or should I just get used to using .getAttribute ()?
javascript html-form
bugmagnet
source share