// our AJAX CFC location CFC = '/model/ajax/registration.cfc'; $().ready( function () { // Housekeeping $('#country').val('United States').click(function(){ $(this).val('');}); // jQuery can't create DOM LABEL elements in IE properly, so we use createElement ProviderLabel = document.createElement("LABEL"); ProviderLabel.htmlFor = "provider"; ProviderLabel.innerHTML = 'Agency Name: * Start typing the first few letters of the agency\'s name and select it from the list. If the agency is not located, start typing Other to select "Other / Not Listed".'; // Input for user to type in their search for provider ProviderInput = ''; // prevents users from clicking submit twice $("#register").submit( function() { $('input:submit').attr('disabled',true).val('Saving Your Registration...'); }); // let's add our dynamic elements to the DOM if($('#providerError').length) divAdd = '#providerError'; else divAdd = '#saveReg'; $(divAdd).before(ProviderLabel).before(ProviderInput).before("
"); //$("#jobtitle").after("
").after(ProviderInput).after(ProviderLabel); // autocomplete AJAX magic plugin at: http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ $("#provider").autocomplete(CFC + "?method=getProvidersAJAX", { width: 300, selectFirst: true, max: 40, multipleSeparator: '|' }); // result callback for autocomplete textbox $("#provider").result( function(event, data, formatted) { if(data) { // providerID 999 = Other / Not Listed provider if($('#providerID').length > 0 || data[1] === 999) $('#providerID').remove(); $('#provider').after($("").val(data[1])); if(data[1] != 999) $('#programs').html('

Select your programs below

'); else $('#programs').html(''); // AJAX to get the program IDs and names for the checkboxes based on the selected providerID $.ajax({ url: CFC, data: { method: 'getPrograms', provider: data[1] }, dataType: "json", success: function(data) { $.each(data, function(i,item) { var cb, cb_label, program = null; cb_label = document.createElement("LABEL"); cb_label.htmlFor = "programIDs"; cb_label.innerHTML = item.VALUE; //cb_label.className = "nobr"; cb = document.createElement("INPUT"); cb.type = "CHECKBOX"; // this sets the checkboxes to checked if called after a failed validation of registration data if(typeof programIDs != 'undefined' && programIDs.length > 0) { for(var i=0;i<=programIDs.length;i++) { if(programIDs[i] == item.ID) { // defaultChecked property is for IE6 & IE7 compatibility cb.defaultChecked=true; break; } } } cb.name = "programIDs"; cb.className = "oldCheckbox"; cb.value = item.ID; $('#programs').append($("

").addClass("label_checkbox").append(cb,cb_label)); }); } }); // end of AJAX call } // end if..then }); // end of provider.result closure // adds class for older browsers that don't support input selectors $('input[type="checkbox"]').addClass('oldCheckbox'); }); // end of document ready function setProviderName(name) { $('#provider').val(name).search(); }