Safari Javascript Caveats
This is not actually related to Perl, the subject I know and love, but I ran into a little javascript issue the other day with Safari.For some reason, I was unable to submit a form programatically using javascript form.submit(). After enabling the safari debug menu and looking at the javascript errors, it was clear that I could not submit the form because the script block had a syntax error and thus would not run properly. Safari does not recognize named access to form elements named ‘for’. As an example:<script language="javascript">var f = document.forms[0];f.for.value = ''; // error: 'for' is looping reserved word.</script>I worked around this by assigning an id attribute to the text box (picking a name that was not a javascript reserved word) and accessing it like so:<script language="javascript">var el = document.getElementById('forElement');el.value = ''; // yay it worked</script>The moral of the story. RFC’s and standards aside, never use reserved words when choosing a name or id attribute for your HTML elements. It may bite you later on.
Blogged with Flock
Tags: javascript, safari , html



