Express Entry:JavaScript

From Melissa Data Wiki
Jump to: navigation, search

← Express Entry Reference

Express Entry Navigation
Introduction
Getting Started
Global Getting Started
Global Terms
Endpoints
ExpressAddress
ExpressCityState
ExpressFreeForm
ExpressPostalCode
ExpressStreet
GlobalExpressAddress
GlobalExpressCountry
GlobalExpressLocalityAdministrativeArea
GlobalExpressFreeForm
GlobalExpressPostalCode
GlobalExpressThoroughfare
Response
XML Response
JSON Response
Global XML Response
Global JSON Response
Token Server
Result Codes
Express Entry Result Codes
Sample Code
US CSharp
US JavaScript
US Visual BASIC
Global CSharp
Global JavaScript
Token Server Support



US REST JavaScript Sample Project


US REST JavaScript Sample Code

<!doctype html>
<html>
<head>
  <title>ExpressFreeForm example</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
  <script type="text/javascript">
    url = "http://expressentry.melissadata.net/";
    id = "<insert user id or license here>";
    jQuery(document).ready(function()
      {
        $('#address').autocomplete(
      {
        showHeader: true, 
        minLength: 4,
        delay: 400,
        source: function(request, response) 
      {
        $.getJSON(url + "jsonp/ExpressFreeForm?callback=?", {format: "jsonp", id: id, FF: request.term, maxrecords: "30"}, function (data)
      {
        //alert(JSON.stringify(data.Results));
        response($.map(data.Results, function( item )
      {
        if(item.Address.SuiteCount == 1)
          return{label: item.Address.AddressLine1 + " " + item.Address.City + " " + item.Address.SuiteName + " " + item.Address.SuiteCount + ", " + item.Address.State + " " + item.Address.PostalCode, value: item.Address.AddressLine1};
        else if(item.Address.SuiteCount > 1)
          return{label: item.Address.AddressLine1 + " " + item.Address.City + " (" + item.Address.SuiteName + " " + "?), " + item.Address.State + " " + item.Address.PostalCode, value: item.Address.AddressLine1};
        else
          return{label: item.Address.AddressLine1 + " " + item.Address.City + ", " + item.Address.State + " " + item.Address.PostalCode, value: item.Address.AddressLine1};
        }));
      });
    },
    select: function(evt, ui) 
      {
        //put selection in result box
        this.form.result.value = ui.item.label;
      }
    });
    $("#clearbutton").click(function() 
     {
        //clear form with a reload
        //window.location.reload(true);
        //or just clear the fields
        this.form.address.value = '';
        this.form.result.value = '';
        //set focus
        $("#postalcode").focus();
      });
    });
  </script>
</head>

<body>
  <div>
    <form onsubmit="return false;"> 
      <table>
        <tr>
          <td>Address:</td> <td><input id="address" type="text" style="padding:2px;width:308px;"></td>
        </tr>
        <tr>
          <td colspan=2><textarea cols="40" rows="6" id="result" style="padding:2px;width:390px;"></textarea></td>
        </tr>
        <tr>
          <td><input id ="clearbutton" type="button" value="Clear"></td><td> </td>
        </tr>
      </table>
    </form>
  </div>
</body>
</html>
Personal tools
Namespaces

Variants
Actions
Navigation
Products
Support