javascript - An input in a form named 'action' overrides the form's action property. Is this a bug? -


i have form marked

<form class="form1" method="post" action="form1.php" style="width:405px"> 

ordinarily, access action of form in javascript referring .action of form object, example

document.forms[0].action 

which return value

form1.php 

however, if have, component of form, item named "action", "action" becomes content of form's action. is, if form markup contains, example,

<input name="action" type="hidden" value="check" /> 

then

document.forms[0].action 

returns value

<input name="action" type="hidden" value="check" /> 

now, did work out how around this: using

document.forms[0].getattribute("action") 

however, it's nasty gotcha confused me long. bug? known gotcha of dom management? or should habit of using .getattribute()?

i not call bug. effect occurs, because attributes can read using element.attributename , named inputs inside form can accessed in same way, formelement.inputname. if there attribute , input same name, there no guarantee 1 used. behaves differently in different browsers.

i use getattribute if reading known attribute included in markup or added using setattribute in javascript. dynamic values like, example, checked attribute of checkbox, don't use getattribute. more question of personal preference, guess.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -