picker and calculator for selecting date ranges

I'm currently working on a hotel booking form where prices are calculated based on the number of adults, seniors, and students. I'm trying to add a date range picker feature that will determine the total cost depending on the selected number of days. However, when I try to include a second calendar for selecting the end date, it doesn't show up. How can I successfully integrate the second calendar so users can select an end date and have the total cost calculated?

update_amounts();
$('select').change(update_amounts);

function update_amounts() {
  var sum = 0.0;
  $('#tickets > tbody  > tr').each(function() {
    var qty = $(this).find('option:selected').val();
    var price = $(this).find('.price').text().replace(/[^\d.]/, '');
    var amount = (qty * price);
    sum += amount;
    $(this).find('.subtotal').text('$' + amount);
  });
  $('#total').val('$' + sum);
  $('#total').val('$')
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<body>
  <table>

    <tbody>
      <tr>
        <td><strong>Adult</strong><a href="#" class="tooltip-1" data-placement="top" title="" data-original-title="16 - 65 years old"><sup class="icon-info-4"></sup></a>
          <span class="price">3,400</span>
        </td>
        <td>
          <div class="styled-select">
            <select class="form-control" name="adults" id="adults">
              <option value="">Select</option>
              <option value="0">0</option>
              <option value="1">1</option>
              <option value="2">2</option>

            </select>
          </div>
        </td>
        <td class="text-center"><span class="subtotal">ksh 0</span>
        </td>
      </tr>
      <tr>
        <td><strong>Senior</strong><a href="#" class="tooltip-1" data-placement="top" title="" data-original-title="Over 65 years old"><sup class="icon-info-4">
    
                                                </sup></a><span class="price">3,400</span>
        </td>
        <td>
          <div class="styled-select">
            <select class="form-control" name="senior" id="senior">
              <option value="">Select</option>
              <option value="0">0</option>
              <option value="1">1</option>
              <option value="2">2</option>

            </select>
          </div>
        </td>
        <td class="text-center"><span class="subtotal">$0</span>
        </td>
      </tr>
      <tr>
        <td><strong>Student >15 yrs</strong> <span class="price">2,000</span> </td>
        <td>
          <div class="styled-select">
            <select class="form-control" name="student" id="student">
              <option value="">Select</option>
              <option value="0">0</option>
              <option value="1">1</option>
              <option value="2">2</option>

            </select>
          </div>
        </td>
        <td class="text-center"><span class="subtotal">$0</span>
        </td>
      </tr>
    </tbody>
  </table>


  <div class="form-group">
    <label>From?</label>
    <input type="text" class="form-control" id="date_pick" name="date_pick" data-date-format="M d, D" placeholder="Select a date">
    <div class="form-group">
      <label>To?</label>
      <input type="text" class="form-control" id="date_pick" name="date_pick" data-date-format="M d, D" placeholder="Select a date">
    </div>
    <div class="form-group">
      <label>Name and Lastname</label>
      <input type="text" class="form-control" id="name_lastname_booking" name="name_lastname_booking" placeholder="Name and Lastname">
    </div>
    <div class="form-group">
      <label>Email</label>
      <input type="email" class="form-control" id="email_booking" name="email_booking" placeholder="Email">
    </div>
    <div class="form-group">
      <label>Telephone</label>
      <input type="text" class="form-control" id="telephone_booking" name="telephone_booking" placeholder="Telephone">
    </div>
    <div class="form-group add_bottom_30">

    </div>
    <div class="form-group">
      <input type="submit" value="Book now" class="btn_full" id="submit-booking">
    </div>


    </form>

</body>

Answer №1

Starting off, I added a beginning tag after the table's end and included the missing closing <div> tag at the form-group's conclusion. The input fields designated to accept dates were originally set as type "text," which I switched to input type="date". Now both inputs display a calendar dropdown feature. To calculate the variance between the two selected dates for pricing purposes, you may utilize JavaScript by referencing a helpful resource like this guide. Alternatively, an open-source tool like Dan Grossman's daterangepicker could be utilized if you prefer selecting both dates within one interface.

I trust this information proves beneficial.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Chrome not displaying fonts properly

Having a font issue in Chrome where specifying "Myriad Pro", Tahoma, Arial results in weird symbols. Works fine in FF, IE, and Safari. Using font-family: Tahoma, Arial; works for all browsers including Chrome. How can Myriad Pro be achieved for IE, FF, a ...

Issue with Fancybox Buttons not appearing on parent page upon opening

I previously asked for help on how to open fancybox from an iframe to the parent page. The solution worked perfectly and is still functioning well. Now, I've been requested to add left and right arrow buttons, but it seems that using the code to open ...

Tips for creating a responsive carousel slider for images

No matter how much I've tried, I can't seem to find a solution on how to make my image responsive along with the caption. Below is my HTML code: <section id="banner"> <div class="banner-bg"> <div class="banner-bg-item ...

Guide on validating React input fields using custom validation methods

Currently, I am working with React and dynamically creating new input fields while utilizing React-hook-form for validation purposes. My approach involves: Having a dropdown with numbers as options, such as 1, 2, 3, 4 Generating input fields based on the ...

How can I assign a true or false value to an input variable in HTML using AngularTS?

I copied the following HTML code: <tag-input fullWidth id="inputDir" formControlName="inputDir" [modelAsStrings]="true" [placeholder]="'choice feature'" ...

Extract table information from MuiDataTable

I am having trouble retrieving the row data from MuiDataTable. When I try to set the index from the onRowSelectionChange function to a state, it causes my checkbox animation to stop working. Below is how my options are currently configured: const option ...

Guide to implementing Jest global Setup and Teardown in a Node.js application

I have integrated Jest tests into my Node.js project, with each test suite containing a beforeAll method that sets up a new test server and connects to a MongoDB database, and an afterAll method that shuts down the server and disconnects from the database. ...

What could be causing app.put() to fail in updating documents within mongodb?

I am currently working on implementing a form in an ejs file where, upon clicking a button, the "likes" attribute of a displayed document from my mongoDB collection should be set to 0 using a "PUT" request. However, for some reason, the document does not u ...

I'm attempting to integrate a 3D model into my React website using Three.js, but I'm encountering errors like 'Failed to parse source map' and other Three.js errors in the console

My goal is to display a 3D model on my website using Threejs and react, but I encountered an error. Upon further investigation, it appears to be an issue with the <Model position={[0.025, -0.9, 0]} /> line in the Model3D.js file. The error occurs wh ...

Fine-tuning Table Filter Javascript

I need help modifying some JavaScript code that currently searches for user input in the first column of a table and hides rows that do not contain that text. I want to update it so that it searches both columns 1 and 2: HTML: <input type="text" id="m ...

"Troubleshooting: Why is TailwindCSS not functioning correctly in my NextJS

My project utilizes a combination of NextJS, TailwindCSS, and Typescript. Strangely, everything displays correctly in the development environment, but once in production, the tailwindcss classes are not being applied. For reference, here is the link to t ...

Check for mobile browser without having to refresh the page

Currently, I am facing an issue with closing the sidebar when the user clicks on Click Me button in mobile view using flexbox layout. The problem arises because the page needs to be refreshed for it to recognize if it's in mobile mode or not by utiliz ...

Creating a customized design for a React application with the use of Scss and JavaScript variables

Is there a method to incorporate JavaScript variables into an SCSS file? For instance, I have a JavaScript file containing the following code: // sky blue const PRIMARY_COLOR = '#489FEF' export { PRIMARY_COLOR} and I would like to utilize it ...

Creating an effective follow-following system in Node.js

I have built a Node.js application that features a basic follow system, allowing users to receive the latest articles from those they follow. The current implementation involves creating an array called followers, which stores the userIDs of all users fol ...

Switching to '@mui/material' results in the components failing to render

I have a JavaScript file (react) that is structured like this: import { Grid, TextField, makeStyles } from '@material-ui/core' import React from 'react' import {useState} from 'react' //remove this function and refresh. see ...

Issue with Bootstrap4 styling for Django forms

I've encountered some challenges when trying to style a form in Django using Bootstrap. I've experimented with different methods but haven't been successful. Does anyone have suggestions on how to style this form using Bootstrap 4? Below i ...

Using JSON.stringify to format data and making an asynchronous $http request

I am working with a JavaScript string that looks like this: user_fav = "21,16"; I need to process this string through a function so that it becomes a JSON array with an id key, like this: {"id":21},{"id":16} This JSON array is then used in an $http req ...

Combining multiple directories into a single output using the rollup command

Alright, let's talk about my directory setup: mods/ -core/ --index.js --scripts/ ---lots of stuff imported by core/index Currently, the typical rollup process works smoothly if you want to create something like mods/core/index.min.js. However, I ha ...

Is there a print button in Drupal similar to a print link?

Is there a way in Drupal to create a button using an API function similar to the print link function? <?php print l(t('Announcement'), 'node/30'); ?> l turns text into a link. I'm looking for a way to create buttons in Drup ...

The Link Breaks the Overlay Hover Effect

Currently, the code functions as intended when you hover over or touch the thumbnail, an overlay will appear. The issue lies in the fact that to navigate to a specific URL, you have to click directly on the text. The overlay itself is not clickable and ca ...