/    Sign up×
Community /Pin to ProfileBookmark

Trying to get a function calling properly

Hi, I’m new to Javascript and Ajax, and I keep getting an error on a line in my html where I am trying to execute a function.

Here’s the html line :

<input type=”button” onclick=”ajaxFunction();” value=”Search”>

I have tried it with ‘ quotes, without ; even copy and pasted the ajaxFunction()
I’m pretty sure that java is enabled in my browser as I have gone through the settings and have jre/jdk installed.

But I keep getting this error :

Line: 78
Char: 1
Error: Object expected
Code: 0
URL: the url of the page

Here’s my Javascript :

[code]
<script type=”text/javascript/” language=”javascript”>
// Browser Support code
function ajaxFunction()
{
var ajaxRequest; // The variable that makes Ajax possible!

try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e){
// Something went wrong
alert(“Your browser broke!”);
return false;
}
}
}

// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById(‘ajaxDiv’);
ajaxDisplay.innerHTML = ajaxRequest.responseText;
// document.getElementById(‘customer’).value = ajaxRequest.responseText
// array ajaxDisplay = document.getElementById(‘customer’);
// ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}

var customer = document.getElementById(‘customer’).value;
var queryString = “?customer=” + customer;
ajaxRequest.open(“GET”, “ajaxCust.php” + queryString, true);
ajaxRequest.send(null);

}
[/code]

Could it be that the data is not being set to be sent? Or I don’t know, any pointers?

Thanks in advance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@scottybwoyauthorOct 11.2006 — Sorry should really have put the input field in too
<i>
</i>&lt;html&gt;
&lt;form name="headmenu" method="POST"&gt;
&lt;input type='text' id='customer'&gt;
&lt;input type="button" onclick="ajaxFunction();" value="Search"&gt;
&lt;/form&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@scottybwoyauthorOct 12.2006 — Probe anyone have any ideas?
Copy linkTweet thisAlerts:
@scottybwoyauthorOct 12.2006 — This still isn't working should be simple really any ideas
×

Success!

Help @scottybwoy 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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