Tuesday, November 21, 2006

Javascript oddity

Has anyone else noticed the following? (I don't know why I ask, as if there's much of an audience to my blog at this point.)

<script type="text/javascript">
var oddity="not so odd";

<input name="oddity" onclick="alert(oddity.value);" type="text" value="rather odd" >

produces an alert that reads "rather odd".

This occurs in Firefox, at least. The interpreter ignores the variable already declared and instead treats the symbol as if it we had referenced the enclosing form element first; i.e.: alert(theform.oddity.value). Rather odd, no?

No comments: