/    Sign up×
Community /Pin to ProfileBookmark

need help using prototype ajax

hi,

i made myself a simple form with 2 text boxes. 1 call city, 1 call county.
upon lose focus on the city text box, i want javascript auto fill the county text box with the correct value.

however, i kept getting “[object XMLHttpRequest]” as the value instead of the actual county value, i must missing a couple minor steps here please help.

[code]
<script src=”prototype.js” language=”JavaScript” type=”text/javascript”></script>

<input type=”text” id=”txtCity” onblur=”checkCounty();” />
<input type=”text” id=”txtCounty” />
[/code]

my code for using prototype is like this:

[code]
function checkCounty(){
var url = ‘ajaxCounty.aspx’;
var param = ‘city=’ + $F(‘txtCity’);
var ajax = new Ajax.Request(
url,
{method: ‘get’,
parameters: param,
onSuccess: function(m_county){
var node = $(‘txtCounty’);
node.value = m_county;
}
});
}//end checkCounty
[/code]

the ajaxCounty.aspx is very simple…just grab the value through http get and do the typical sql query, then spit the value through response.write….

i think i not using new Ajax.Request correctly, would someone please help point out where i did wrong?

thank you.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@sirpelidorauthorMar 19.2007 — blah.... if i think i got that figured it out ?

[object XMLHttpRequest] obviously is a javascript object, after i google around for its property, then i found out i can use "responseText".

so all i need is:
<i>
</i>var ajax = new Ajax.Request(
url,
{method: 'get',
parameters: param,
onSuccess: function(m_county){
var node = $('txtCounty');
node.value = m_county.responseText;
}
});


is there a cleaner way to do it? somehow i feel "responseText" is just a quick and dirty way....

thank you
×

Success!

Help @sirpelidor 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.14,
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,
)...