On Tue, Mar 07, 2006 at 10:01:32PM -0500, Jerod Venema wrote:
> As to the other question...it could be a scope issue. I'd have to see it in
> an example to be of much help, but from the code you've posted, "this" would
> refer to the document window. Assuming the function is not wrapped in some
> other object, ie, its just freestanding in the document...
I must have copied some code from someplace. In Firefox "this" was
the element that caused the event.
I'll post the code just in case I'm doing anything else wrong. ;)
Oh, I guess the .replace doesn't need to be inside the callback
function.
function ZipLookup(event) {
/* Should use regex and allow for zip+4 */
var e = Event.element(event);
if ( e.value.length != 5 ){
return;
}
if ( isNaN(e.value) ) {
alert( "Zipcode should be a number" );
return;
}
var this_id = e.id;
var cb = function(originalRequest){
var ret = eval("(" + originalRequest.responseText + ")" );
var json = ret.json;
if ( !json ) { return }
var prefix = this_id.replace(/zip$/,'');
var state = $( prefix + 'state' );
var city = $( prefix + 'city' );
if ( !state || !city ) {
alert( "failed to find city/state elements ");
return;
}
if ( json.state && json.city ) {
state.value = json.state;
city.value = json.city;
}
return;
}
new Ajax.Request( url, {
method: 'get',
onComplete: cb
} );
}
--
Bill Moseley
[EMAIL PROTECTED]
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs