/    Sign up×
Community /Pin to ProfileBookmark

Not A Function

When I try to run the following script, I get the following error:

[quote]

Error: fileSearch is not a function
Source File: [url]http://localhost:8081/file:/C:/Documents%20and%20Settings/test/My%20Documents/My%20Web%20Sites/home/file/docupload.php?DBGSESSID=-1&PHPEdHidden=23258[/url]
Line: 1

[/quote]

The function is included in an external javascript page, and every other function on that page works properly. This one however always returns that error, even if I comment out the entire function and just create put in an “alert”.

The function:

[code=php]
function fileSearch() { /*
var form = document.fileform;
var resultTable = document.getElementById(“linkSearchResults”);
var fileId = form.id.value;

var qry = “searchMethod=id&userQuery=” +fileId+ “&time=” +time;

xmlHttpOpen();

ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 1) {
resultTable.innerHTML = “<tr><td colspan=’2′>Searching…</td></tr>”;
}
if (ajaxRequest.readyState == 4) {
resultTable.innerHTML = ajaxRequest.responseText;
}
}

ajaxRequest.open(“POST”, “fileSearch.php”, true);
ajaxRequest.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded; charset=UTF-8″);
ajaxRequest.send(qry); */

alert(“Is a function”);
}[/code]

And how I call it:

[code=html]
<input type=”button” class=”gloss” value=”Search” name=”search” onclick=”fileSearch()”>[/code]

I think I’m having a case of the mondays.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@toicontienAug 27.2007 — The code you posted appears correct, so something else must be going on. If you declare a variable with the same name as the function, the variable may over write the function:
function fileSearch() {
...
}

var fileSearch = 'foo';

In the onclick for the button, try this code:
alert(typeof(fileSearch));
Copy linkTweet thisAlerts:
@FangAug 28.2007 — or there is a missing bracket in a previous function.
Copy linkTweet thisAlerts:
@TJ111authorAug 28.2007 — I searched through all the files for the word "fileSearch", it turns out that my search field name was "fileSearch". I have a question though. When I did the "typeof" alert, it alerted object. Since in javascript objects are functions and functions are objects, wouldn't that refer to the function? Or was it referring to the HTML object?
Copy linkTweet thisAlerts:
@Arty_EffemAug 28.2007 —  I have a question though. When I did the "typeof" alert, it alerted object. Since in javascript objects are functions and functions are objects, wouldn't that refer to the function? Or was it referring to the HTML object?[/QUOTE]Had it been a function, it would have returned type 'function'.
Copy linkTweet thisAlerts:
@toicontienAug 28.2007 — It sounds like you've got a JavaScript variable named "fileSearch". Try this:
alert(fileSearch.nodeName)
I can't imagine Internet Explorer would be creating a global window object property for each form element it creates. There must be a JavaScript variable on the page called fileSearch that you're using.
Copy linkTweet thisAlerts:
@TJ111authorAug 29.2007 — No I did a search through the document, the only other place "fileSearch" exists is in the ajax call to fileSearch.php, which is a string and not a variable, and on the HTML page with the input filed named "fileSearch". After renaming the function, I have had no issues with it.
×

Success!

Help @TJ111 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...