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.
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.
Share Improve this question edited Jul 3, 2011 at 17:27 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jul 3, 2011 at 16:02 newbiejspersonnewbiejsperson 1234 bronze badges1 Answer
Reset to default 15Some 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.