getting "xxx is not a function" in JS
here's a little code I try to run on Firefox:
<html>
<head>
<title>Ex4: My Sequence Finder</title>
<script type="text/javascript">
function action() {
alert("action");
if (formValidation() == false)
return;
}
function searchInput() {
alert("searchInput");
return;
}
</script>
</head>
<body>
<font face="arial" size="5" color="blue">Input section</font> <br/>
<p>Query Sequence</p>
<form name="form">
<textarea id="input" rows="8" cols="60"></textarea><br/>
<textarea id="enhancers" rows="4" cols="30"></textarea><br/>
<textarea id="si开发者_如何学Pythonlencers" rows="4" cols="30"></textarea><br/>
<input type="button" value="button1" onclick="action()" />
<input type="button" value="button2" onclick="searchInput()" />
<div id="results"></div>
</form>
</body>
</html>
As you can see one of the button calls searchInput() and that works fine, the other is supposed to call action(), but I get "action() is not a function". Btw they both just call alert() at this point, so I know it got in the function.
I have no idea as to why this happens, any help would be great. Thanks!
Form elements have an action
attribute (specifying the URI that should process the form data).
This attribute name "overrides" the javascript function name, causing the error you see.
Rename your function to something else and it will work.
You can solve this by using
var function1 =new function(){
var action=new function() {
alert("action");
if (formValidation() == false)
return;
}
}
<input type="button" value="button1" onclick="function1.action()" />
action
calls formValidation
which doesn't seem to be a function. Maybe the parser took this error and chose not te register action as a function because of it.
精彩评论