topical media & game development

talk show tell print

professional-ajax-10-DWR-Demo-CustomerClient-Dwr.htm / htm



  <html>
  <head>
    <title>DWR Test</title>
    <script type="text/javascript" src="/DwrTest/dwr/interface/Customer.js"></script>
    <script type="text/javascript" src="/DwrTest/dwr/engine.js"></script>
    <script type="text/javascript" src="/DwrTest/dwr/util.js"></script>
    <script type="text/javascript">
  
    function fetchAddress(Email)
    {
      if (!Email)
      {
        alert("Please enter your email address before choosing an item.");
        $("txtEmail").focus();
        return;
      }
      Customer.getAddressFromEmail(Email, callback);
    }
  
    var callback = function (Address)
                   {
                     showAddress(Address);
                   };
  
     function showAddress(Address)
     {    
      $("txtForenames").value = replaceIfNull(Address["forenames"], "");
      $("txtSurname").value = replaceIfNull(Address["surname"], "");
      $("txtAddress1").value = replaceIfNull(Address["address1"], "");
      $("txtAddress2").value = replaceIfNull(Address["address2"], "");
      $("txtAddress3").value = replaceIfNull(Address["address3"], "");
      $("txtAddressTown").value = replaceIfNull(Address["addressTown"], "");
      $("txtAddressStateCounty").value = replaceIfNull(Address["addressStateCounty"], "");
      $("txtAddressZipPC").value = replaceIfNull(Address["addressZipPC"], "");
      $("txtAddressCountry").value = replaceIfNull(Address["addressCountry"], "");
      if (!Address["success"])
        {
        alert(Address["error"]);
        alert("Address not registered, please fill in details.");       
        $("txtForenames").focus();
      }
    }
  
    function replaceIfNull(Value, ReplaceWith)
    {
      if (Value == null)
      {
        return ReplaceWith;
      }
      return Value;
    }
  
    </script>
  </head>
  <body>
    <table width="60%" align="left">
      <tbody>
        <tr>
          <td width="25%">Enter your email address:</td>
          <td width="75%">
            <input type="text" id="txtEmail" size="30"
                   value="hmqueen412@yahoo.com" 
                   onblur="fetchAddress($('txtEmail').value);">
          </td>
        </tr>
        <tr>
        <tr>
          <td>Choose an item:</td>
          <td>
            <select>
              <option>Lear Jet</option>
              <option>Rolls Royce Car</option>
              <option>Luxury Yacht</option>
              <option>Wrox Book</option>
            </select>
          </td>
        </tr>
          <td>Forenames:</td>
          <td><input type="text" id="txtForenames" size="50"></td>
        </tr>
        <tr>
          <td>Surname:</td>
          <td><input type="text" id="txtSurname" size="50"></td>
        </tr>
        <tr>
          <td>Address 1:</td>
          <td><input type="text" id="txtAddress1" size="50"></td>
        </tr>
        <tr>
          <td>Address 2:</td>
          <td><input type="text" id="txtAddress2" size="50"></td>
        </tr>
        <tr>
          <td>Address 3:</td>
          <td><input type="text" id="txtAddress3" size="50"></td>
        </tr>
        <tr>
          <td>Town/City:</td>
          <td><input type="text" id="txtAddressTown" size="50"></td>
        </tr>
        <tr>
          <td>State/County:</td>
          <td><input type="text" id="txtAddressStateCounty" size="50"></td>
        </tr>
        <tr>
          <td>ZIP/Post Code:</td>
          <td><input type="text" id="txtAddressZipPC" size="50"></td>
        </tr>
        <tr>
          <td>Country:</td>
          <td><input type="text" id="txtAddressCountry" size="50"></td>
        </tr>
      </tbody>
    </table>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.