I have a form with a select dropdown, and my select tag looks like this:
<select name='preset' onchange='preset(this);'>
Right now I have my JavaScript function just do alert('test');
. Well, when I change my selection in the dropdown, I'm getting an error saying "preset is not a function". Yes, I verified that it's spelled right, and I even did a generic call to it on page load and got my alert.
If I change my function name to something else, like presetx
it works just fine. So I thought maybe "preset" was some kind of reserved word in JavaScript, but I can't seem to find anything saying as such. Why would this happen?
Update
Currently I don't have anything else on my test page except for my form and the function. No framework includes or other code, so I know it's not anything like that.
Some browsers map elements with name
attributes to global variables. So <select name='preset' onchange='preset(this);'>
actually creates (in some browsers) a global property preset
. This overwrites the preset
function.
Since preset
is now an HTMLSelectElement object, not a function, you get a "not a function" error.
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