Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering jQuery UI
Mastering jQuery UI

Mastering jQuery UI: Become an expert in creating real-world Rich Internet Applications using the varied components of jQuery UI

Arrow left icon
Profile Icon Joshi
Arrow right icon
₱2806.99
Paperback Feb 2015 312 pages 1st Edition
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
Arrow left icon
Profile Icon Joshi
Arrow right icon
₱2806.99
Paperback Feb 2015 312 pages 1st Edition
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Mastering jQuery UI

Chapter 1. Designing a Simple Quiz Application

To begin with, we will design a simple quiz application where users have to match country names to their corresponding capital names by dragging a country name over its correct capital. A correct match will result in one point, and drag and drop will be disabled for both the country and its capital.

The display will contain two columns, the first one will have country names and the second one will have the names of the capitals of those countries. Both the columns will be shuffled randomly. Once the user has matched all the names successfully, a modal dialog will appear. Users will also be given the option to reset the quiz. Resetting will restart the game and shuffle the lists again.

Setting up jQuery UI

We will need the jQuery and jQuery UI libraries before going ahead. Throughout this book, we'll use jQuery Version 1.10.2 and jQuery UI Version 1.10.4 with the UI lightness theme . Note that the jQuery UI files also contain a copy of the jQuery source file.

Downloading the required files

To download jQuery, visit the download page on the jQuery website at http://jquery.com/download/.

Tip

Make sure that you download the correct version as per your requirements.

For jQuery UI, visit the download page at http://jqueryui.com/download/ to download the jQuery UI library.

Tip

Since we will cover all components throughout the book, download the full version of the library.

Using jQuery/jQuery UI libraries with a CDN

You might be aware that Content Delivery Networks (CDN) host many popular libraries. Since the browsers cache JavaScript files, your page will not have to load a JavaScript file again if it is referenced from a CDN and already cached in browser. You can link jQuery and jQuery UI among CDN's many other libraries.

Tip

Make sure that you are connected to the Internet if you have referenced the libraries from the CDN in your pages.

Google, Microsoft, and some other companies provide CDN for jQuery, jQuery UI, and other libraries. Here are the links to pages for downloading these libraries:

Setting up the folder structure for the JavaScript and CSS files

We will now set up the folder structure that we will use for all the chapters in this book. The steps are as follows:

  1. In your document root, create a folder named MasteringjQueryUI. Then, create a folder for each chapter inside it.
  2. For this chapter, create a new folder named Chapter1 inside MasteringjQueryUI and two more folders named js and css inside the Chapter1 folder.
  3. Now extract the jQuery UI files into a separate folder and go to its js folder. You will see three files: jQuery source file and full and minified versions of jQuery UI.
  4. Copy the jQuery source file and any one version of jQuery UI source files and place them inside the js folder that you created inside Chapter1 of the MasteringjQueryUI folder.
  5. Also, copy the ui-lightness folder from the css folder from the downloaded jQuery UI to the css folder of Chapter1.

Now we are ready to experiment with jQuery UI and create some informative and fun examples. Let's start our journey by creating the quiz application.

Creating the layout

In the newly created folder Chapter1, create a file named index.html and another .js file named quiz.js inside the js folder of Chapter1. The quiz.js file will contain all the code that we need to make the quiz functional.

Markup for the quiz page

Open the index.html file for editing using your favorite text editor, and write the following code in it:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Designing a simple quiz application</title>
    <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.10.4.custom.min.css">
  </head>
  <body>
    <div class="container">
      <span id="score"></span>
      <button id="reset" type="button">Reset</button>
      <div class="clear"></div>
      <hr/>
      <div id="leftCol">
        <ul id="source">
        </ul>
      </div>
      <div id="rightCol">
        <ul id="target">
        </ul>
      </div>
    </div>

    <div id="dialog-complete" title="Well Done!">
      <p><span class="ui-icon ui-icon-check"></span>
      Well done. You have completed the quiz successfully.</p>
    </div>

    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/jquery-ui-1.10.4.custom.min.js"></script>
    <script src="js/quiz.js"></script>


  </body>
</html>

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

In the preceding code, inside the head section, we referenced the jQuery UI .css file. If you have placed the .css file elsewhere, make sure to correct the path accordingly. The path can either be an absolute path or a relative path.

Inside the body, we have a div element named container that wraps our entire markup. Inside container, we have created two span elements. The first span has the id value score and it will be used to show the score of the user. The second span has the id value reset and it will be used to reset the quiz to its initial state.

After this, we have to create two more div elements having the id value leftCol and rightCol, respectively. leftCol has an ul element with the id value source inside it. This ul element will contain the names of countries as list items. Similarly, rightCol has another ul element with the id value target inside it. It will have the names of capitals as list items.

After the container element, we have created yet another div element with the id value dialog-complete, which will be displayed once the user has completed the quiz successfully. Inside the dialog-complete element, we have placed a success message.

Finally, at the bottom of the page, reference the jQuery, jQuery UI, and quiz.js files.

Note

Make sure that jQuery is included first before jQuery UI, and that any other JavaScript file or custom jQuery code is included or written.

Styling elements

We will also need some CSS styling to make the elements look good. In the head section of the index.html file, write the following code:

<style type="text/css">
  body{
    font-family:arial,verdana;
    font-size:12px;
    margin: 0px auto; 
    width: 600px;
  }

  div.container{
    border: 1px solid #000;
    float:left;
    margin:0 auto;
    padding:10px;
    width: 100%;
  }

  #leftCol{
    float:left;
  }

  #rightCol{
    float:right;
  }

  ul{
    list-style:none;
    margin:0;
    padding:0;
    width:50%;
  }

  li{
    border:1px solid #000;
    font-weight:bold;
    margin:5px 0;
    padding:10px 0;
    text-align:center;
    width:175px;
  }

  #source li{
    cursor:move;
  }

  #score{
    font-weight:bold;
    float:left;
    color:#ff0000;
  }

  #reset{
    color:#ff0000;
    cursor:pointer;
    font-weight:bold;
    text-align:right;
    text-decoration:underline;
    float:right;
  }

  .clear{
  clear:both;
  }

  #dialog-complete{
    display:none;
  }

  #dialog-complete span{
    float:left;
    margin:0 7px 20px 0;
  }
</style>

In the preceding code, first we defined some basic styles for the body and the container elements. After that, the styles were defined for the ul element and its li items. These styles will display the list items in the form of individual boxes. CSS for the score and reset items follow next and finally some basic styling for the dialog elements.

Making the quiz functional

Our UI part is now complete and we can proceed to make the quiz functional. We will do this in a few steps. First of all, we will display the data on the page in two columns. Then, we will make the country names draggable. Finally, the list items with the capital names will be made droppable so that we can drop a country name inside a capital. We will also have to ensure that a droppable capital name accepts only the correct country name. Finally, the resetting logic will be built.

Displaying data on the page

Open the quiz.js file for editing and write the following code:

$(document).ready(function()
{
  createQuizLayout();
});

On the document ready event we call a function named createQuizLayout which we need to define now.

function createQuizLayout()
{
  //declare arrays of countries and their capitals.
  var countries = ["USA", "UK", "India", "Germany", "Turkey", "France", "Nepal", "Japan", "South Africa", "Maldives"];
  var capitals = ["Washington", "London", "Delhi", "Berlin", "Istanbul", "Paris", "Kathmandu", "Tokyo", "Capetown", "Male"];

  var arrCountry = [];
  for(var i=0; i<countries.length; i++)
  {
    arrCountry.push('<li data-index="' + (i+1) + '">' + countries[i] +'</li>');
  }

  var arrCapital = [];
  for(var i=0; i<capitals.length; i++)
  {
    arrCapital.push('<li data-index="' + (i+1) + '">' + capitals[i] +'</li>');
  }

  //shuffle the arrays
  arrCountry = shuffle(arrCountry);
  arrCapital = shuffle(arrCapital);
  // once country and capital items are ready, we insert them into DOM
  $('#source').html(arrCountry.join(''));
  $('#target').html(arrCapital.join(''));
}

Here is what the preceding code does:

  • We have defined two arrays named countries and capitals.
  • The countries array contains names of 10 countries and the capitals array contains names of the capitals of the countries defined in the countries array. The names of capitals must be in the same order as their respective countries.
  • Since we want to display the names of countries and capitals in a random order, we will create two arrays and fill them with list items and shuffle them.
  • We started with country first. We declared an array named arrCountry. Then, we loop in the countries array and create a list item with the country name and push it into the arrCountry array.
  • The same process is repeated for the capitals array.

An important point to note here is that we are giving a data attribute named index to each list item having a value from 1 to 10. Since we have both the countries and capital names in the same order, index will be used to match which country belongs to which capital.

After both arrays are populated, we will shuffle them so that the order of countries and capitals becomes random. For this, we will use a simple shuffle function from the website http://jsfromhell.com/array/shuffle. The shuffle function is defined as follows:

function shuffle(o)
{
  for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
};

After calling the shuffle function on both arrays arrCountry and arrCapital, the array elements are inserted in DOM after combining them into a single string using the JavaScript join function. The elements in the array arrCountry are inserted in ul with the id value source and those in the array arrCapital are inserted in ul with the id value target.

Open your browser and point it to the index.html file of the Chapter1 folder now. You will see a page similar to the one shown in the following screenshot:

Displaying data on the page

If you reload the page, you will see that the order of countries and capitals changes each time. This is because shuffling creates a new order for items of both lists.

Draggable country names

To make the country names draggable, we will use the draggable component of jQuery UI. As the name suggests, the draggable component allows DOM components to be moved around using a mouse. To do this, go to the $(document).ready() section of our quiz.js file and call another function named initQuiz. The $(document).ready() callback function should look like this now:

$(document).ready(function()
{
  createQuizLayout();
  initQuiz();
});

Now define the initQuiz function outside document ready handler as follows:

function initQuiz()
{
  $('#source li').draggable(
  {
    revert : true,
    revertDuration: 200,
    cursor: "move"
  });
}

The preceding code calls the draggable method of the jQuery UI library. It is being called upon the li elements of the ul source, which means it will make all the list items draggable inside the source ul. Further, we are also giving the draggable method three options that we need for our application: revert, revertDuration, and cursor. Let's look at these in more detail:

  • revert: This decides whether the element being dragged should revert to its original position or not. In our case, we will set it to true. We will drag a country name onto a capital name and revert it to its original position, that is, the country list. Another possible value for revert is false, which means it will stay at the place where it is when dragging stops. The values, valid and invalid, can also be provided (as strings) for the revert option. The value valid means the draggable object will revert only if the draggable object has been dropped on a droppable element. The value invalid means the draggable fuction will revert if the draggable object has not been dropped. Alternatively, a function can also be provided to revert. This is required in complex cases where we need to perform any manipulations. The return value for this function will decide if it will revert or not. If true is returned, the element will revert.
  • revertDuration: This defines the duration for the revert option in milliseconds. The lower the value, the faster it will revert. This value is not considered if the revert option is set to false.
  • cursor: This is the style of cursor while an element is being dragged.

Our draggable elements are ready now, and so it is time to make the capital names droppable and build the logic to match countries to their correct capitals.

Droppable capital names and scoring

In the previous section, we created an initQuiz function where we made our countries draggable. After the draggable code, write the following code to make the capitals droppable:

var totalScore = 0;
$('#score').text(totalScore + ' points.');
$('#target li').droppable(
{
  accept : function(draggable)
  {
    if(parseInt(draggable.data('index'), 10) === parseInt($(this).data('index'), 10))
    {
      return true;
    }
    else
    {
      return false;
    }
  },
  drop: function( event, ui ) 
  {
    var that = $(this);
    that.addClass( "ui-state-highlight" ).html( 'Correct!' ).effect('bounce');
    that.droppable('disable');
    ui.draggable.addClass('correct ui-state-error');
    (ui.draggable).draggable('disable');

    totalScore++;
    $('#score').text(totalScore + ' points.');
    if($('li.correct').length == 10)
    {
      $( "#dialog-complete" ).dialog({
        resizable: false,
        modal: true
      });
    }

  }
}); 

Now save the quiz.js file and refresh your browser. You will be able to drag the country names now. Drag a country name to its correct capital and you will see that the country will revert to its original position. The capital list item will show a bounce effect and its text will change to Correct!. Both the country and capital names will be disabled now. You will not be able to drag the country name as well. On the top left hand side, the page will show the score as 1 points.

The screen will look like the following screenshot:

Droppable capital names and scoring

Try the drag and drop for all countries in the left-hand side list. When you have matched all countries correctly, you will see a dialog box and the page will look like the following screenshot:

Droppable capital names and scoring

So, a lot is happening in the preceding code. We will look at it step by step.

We defined a variable named totalScore and set it to 0. We also inserted the score inside the HTML element with the id value score. Each time the quiz starts, the score will be reset as well. After this, we call the droppable method of jQuery UI on the list items of ul with the id value target to make them ready to accept the draggable country elements.

We are using the accept option of the jQuery UI draggable method to check for the correct matches of country and capital, and we are using the drop event to change the UI and scoring.

Accepting a draggable element

The accept option of a droppable method defines which draggable element will be accepted by the droppable method when a draggable element is over it; either a jQuery selector or a function can be provided for this purpose. If a selector is given, only the draggable element matching that selector will be accepted by the droppable method. Since we want to match an individual country to its capital, it is better for us to use a function instead. The function will receive the current draggable element that is being dragged as a parameter. Inside the function, $(this) will refer to the current droppable element. The code is as follows:

if(parseInt(draggable.data('index'), 10) == parseInt($(this).data('index'), 10))
  {
    return true;
  }
  return false;

Since we have already defined data attributes for both countries and capitals, we can match those to check if the current draggable-droppable pair is a correct country-capital pair or not. If the indexes match, we return true; otherwise, we return false.

A return value true means the droppable method will accept the draggable element, and will allow the draggable element to be dropped in it.

The drop event

The drop event will receive a draggable element once it has been passed from the accept option. If the accept option returns false for any draggable element, then the drop event will not be called. In our case, this means we will only receive a country's draggable element and its corresponding capital's droppable element.

The callback function for the drop event receives two parameters: event and ui. Of these two, we are interested in the ui object. Among other values, it provides us with a reference to the draggable element that was dropped. To refer to the current droppable element where the draggable element is dropped, we have $(this) variable with us. The code is as follows:

$( this ).addClass( "ui-state-highlight" ).html( 'Correct!' ).effect('bounce');
$( this ).droppable('disable');

In the preceding code, we added the jQuery UI framework's CSS class ui-state-highlight to the current droppable element and then changed that list item's HTML content to Correct! and added the bounce effect to the droppable capital.

Since the droppable capital has been matched successfully with its country, we no longer need it as a droppable element. Hence, the preceding code uses the disable method of the droppable component to disable the droppable functionality.

The next two lines add CSS classes named correct and ui-state-error to the draggable method and then disable it. The code is as follows:

ui.draggable.addClass('correct ui-state-error');
(ui.draggable).draggable('disable');

The correct class will be used to determine how many successful countries have been matched. The class ui-state-error is just for presentation purposes to make the successfully matched country name highlighted. Using the draggable disable method, we disable the specific draggable element as well, because it has been matched and we do not want it to be dragged again.

Since the drop event receives only the accepted draggable elements, we can safely increase the variable totalScore by 1 and insert the new value back to the DOM in the element score. This shows us the latest score each time a new match is made.

Finally, we count the number of list items in the countries' column that have the CSS class named correct associated with them. Since we have 10 elements, if all the 10 list items have the CSS class correct attached to them, it means the quiz is complete. We then show a jQuery UI dialog component that we kept hidden in our HTML page initially.

Resetting the quiz

If you were wondering why we created the functions createQuizLayout and initQuiz when we wrote the code without them, the answer is that we need to call them again. It is better not to repeat yourself. We can now reset the quiz without having to reload the page.

We have already created an element with id reset. Visit the $(document).ready() callback again and write the following code after those two function calls. The section will now look like this:

$(document).ready(function()
{
  createQuizLayout();
  initQuiz();

  $('#reset').on('click', function()
  {
    $('#source li').draggable('destroy');
    $('#target li').droppable('destroy');
    createQuizLayout();
    initQuiz();
  });
});

We have an event handler registered at the click of the reset button. It is using the destroy method of jQuery UI on the draggable and droppable elements. The destroy method will remove the complete draggable and droppable functionality from respective elements. It will also remove any special CSS classes that jQuery UI might have applied earlier.

After bringing the page to its initial state, we call the createQuizLayout and initQuiz functions again, which will initialize our quiz once more.

Improving the quiz

This was a basic application to begin with. There can be many more enhancements to this quiz to make it more feature rich. You are encouraged to add more features to it and refactor the code as well.

Here are some ideas that you can start with:

  • Remove successfully matched countries and capitals
  • If you watch closely, we do not need the variable totalScore

    Tip

    List items with the class correct are enough for calculating scores.

  • Allow negative scoring if the user drops the country in an incorrect capital

Summary

The draggable and droppable methods are important components of jQuery UI in order to make interactive applications. We explored a few options presented by these two components and created a simple quiz application in this process. We will see more options presented by these two components in the following chapters as well, where we will create a jigsaw puzzle game.

Left arrow icon Right arrow icon

Description

If you are a frontend developer with considerable knowledge of jQuery UI and want to take this expertise to the next level, then this book is for you.

Who is this book for?

If you are a frontend developer with considerable knowledge of jQuery UI and want to take this expertise to the next level, then this book is for you.

What you will learn

  • Create mashups using APIs of popular websites such as Reddit and Google Maps
  • Integrate AJAX with different components
  • Create projects that solve realworld problems and are not theoretical
  • Discover the best usage of components in a given situation
  • Use effects to make the UI more interactive
  • Use JSONP to make crossorigin AJAX requests
  • Get to grips with best practices to use while developing with jQuery UI
Estimated delivery fee Deliver to Philippines

Standard delivery 10 - 13 business days

₱492.95

Premium delivery 5 - 8 business days

₱2548.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 25, 2015
Length: 312 pages
Edition : 1st
Language : English
ISBN-13 : 9781783286652
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Philippines

Standard delivery 10 - 13 business days

₱492.95

Premium delivery 5 - 8 business days

₱2548.95
(Includes tracking information)

Product Details

Publication date : Feb 25, 2015
Length: 312 pages
Edition : 1st
Language : English
ISBN-13 : 9781783286652
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 8,114.97
Mastering jQuery Mobile
₱2806.99
jQuery 2.0 Development Cookbook
₱2500.99
Mastering jQuery UI
₱2806.99
Total 8,114.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Designing a Simple Quiz Application Chevron down icon Chevron up icon
2. Building a Jigsaw Puzzle Game Chevron down icon Chevron up icon
3. Creating a Website Tour Chevron down icon Chevron up icon
4. Creating a Tabbed News Reader Chevron down icon Chevron up icon
5. Implementing CAPTCHA using Draggable and Droppable Chevron down icon Chevron up icon
6. Creating an Event Timeline Using a Slider Chevron down icon Chevron up icon
7. Using jQuery UI with Google Maps API Chevron down icon Chevron up icon
8. Creating a Photo Album Manager Chevron down icon Chevron up icon
9. Creating Widgets Using the Widget Factory Chevron down icon Chevron up icon
10. Building a Color Picker with Hex RGB Conversion Chevron down icon Chevron up icon
11. Creating a Fully Functional Dashboard Chevron down icon Chevron up icon
A. Best Practices for Developing with jQuery UI Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela