Require assistance in getting a slider operational

Hello there! I could really use your assistance with this code. I have been trying to make it work using JavaScript, but I'm determined not to incorporate any external JS files.

Here is the snippet of JavaScript code I am working with:

"use strict";
var $ = window.jQuery;

// BEDROOM_RATES object
var BEDROOM_RATES = {
    b1 : 99,
    b2 : 119,
    b3 : 139,
    b4 : 169,
    b5 : 189,
    b6 : 229
};
var PER_BATHROOM = 20; 

// Rest of the JavaScript functions and event handlers go here...

Also, below is the CSS styling for a front slider that you can check out in action on this demo link:

Check demo working on 
http://getondesk.com/demo/zenclean/

Its a front slider

I want to avoid external JavaScript files altogether and rely solely on inline scripts for functionality. Can anyone guide me on how to achieve this? Your help would be greatly appreciated!

Answer №1

Here's a creation of mine that I put together in about 30 minutes xD. Please check it out on Code Pen. Make sure to view it in FULL SCREEN MODE:

var room = document.getElementById("bedNumber").getContext("2d");
var stay = document.getElementById("stayNumber").getContext("2d");

room.beginPath();
room.fillStyle = "red";
room.fillRect(20, 0, 30, 10);

stay.beginPath();
stay.fillStyle = "red";
stay.fillRect(20, 0, 30, 10);

var RoomNumber = 0;
var StayNumber = 0;
var Lux = 0;

function chose(context, event) {
  var X = event.clientX - 80;
  if (context == "room") {
    room.beginPath();
    room.fillStyle = "red";
    room.clearRect(0, 0, 1000, 50);
    room.fillRect(X, 0, 30, 10);
    RoomNumber = X / 2;
  } else {
    stay.beginPath();
    stay.fillStyle = "red";
    stay.clearRect(0, 0, 1000, 50);
    stay.fillRect(X, 0, 30, 10);
    StayNumber = X;
  }
  Price();
}

function addLuxury(lux) {
  Lux = lux * 50;
  Price();
}

function Price() {
  var Total = RoomNumber + StayNumber + Lux;
  document.getElementById("total").innerHTML = "BUY ROOM(S) FOR " + Total + "$";
}
#slider {
  background-color: rgba(0, 0, 0, 0.3);
  width: 600px;
  height: 400px;
}
h1 {
  color: white;
  text-align: center;
}
u {
  color: white;
}
canvas {
  border: 2px solid black;
  margin-left: 50px;
  background-color: white;
}
button {
  background-color: #0099ff;
  border-radius: 25px;
  margin: 8px;
}
#total {
  background-color: #6666ff;
  border-radius: 25px;
  text-align: center;
}
<body>
  <div id="slider">
    <u><h1>Hotel Rooms For Good Price</h1></u>
    <br/>ROOMS :
    <canvas id="bedNumber" width="500" height="10" onclick="chose('room', event)"></canvas>
    <br/>
    <br/>STAY :
    <canvas id="stayNumber" width="500" height="10" onclick="chose('stay', event)"></canvas>
    <br/>
    <u><h3>Luxury</h3></u>
    <button onclick="addLuxury(0)">LUXURARY : BAD
      <br/>+0$ per/D</button>
    <button onclick="addLuxury(1)">LUXURARY : OK
      <br/>+75$ per/D</button>
    <button onclick="addLuxury(2)">LUXURARY : WOW
      <br/>+150$ per/D</button>
    <button onclick="addLuxury(3)">LUXURARY : BEST
      <br/>+215$ per/D</button>
    <br/>
    <br/>
    <br/>
    <button id="total">BUY ROOM(S) FOR $0</button>
  </div>
</body>

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

The reply from the Servlet webpage is displayed on a fresh page

I am currently using Ajax and jQuery to handle the dynamic form submission process. While everything is functioning correctly, I am encountering an issue where the response from the Servlet is being displayed on a separate page. function initiateFormSubm ...

Populate your HTML with JSON data

I need some guidance on how to achieve a specific task. I have a PHP file that retrieves data from a MySQL database and returns it in JSON format. Now, I want to display this data in HTML with "data_from_json" replaced by "18.5". Any assistance would be gr ...

Having trouble getting the reset select function to work

I'm in the process of developing a website where I'm facing an issue with resetting my form that is constructed using jQuery Uniform. Despite my efforts, I am unable to successfully reset it. Below is the header code snippet: $j(function() { ...

Using ServiceStack to deserialize an array

My goal is to post the following data to my ServiceStack web service: $.ajax({ url: 'http://localhost:8092/profiles', type:'POST', data: { FirstName : "John", LastName : "Doe", Categories : [ "Catego ...

Is there a way to dynamically update the polyline on the map when I drag a marker to change the path, removing the previous one in the process?

I'm still fairly new to working with Javascript and the Google Maps API. I've come across various solutions to a similar issue that I'm facing, but none of them seem to work for my specific code. I'm starting to question whether the pol ...

Is d3 Version pretending to be a superior version?

I have encountered an issue with my project that involved using d3 v5.5.0. After transferring it to a different computer and running npm install, the application now seems to be recognizing d3 as a higher version? A crucial part of my program relies on th ...

A method of submitting by simply pressing the enter key alongside clicking on a Bootstrap button

Here is the HTML code I am using to input prompts into a chatbot: <div class="input-group mb-3"> <input type="text" class="form-control" id="chat-input"> <div class="input-group-append ...

Tips for writing an async function using TypeScript

I've been working with Typescript and NLP.js. However, I'm encountering an issue where the argument manager is displaying 'Parameter manager implicitly has an any type'. I attempted to use :, but it didn't solve the problem eff ...

Error thrown: SyntaxError - Forbidden break statement in AJAX code execution

Trying to exit a loop nested within a statement has been a challenge. Despite researching similar questions on stackoverflow, I have not found a solution that works. Below is the current code in question: for (var i = 0; (i < 10); i++) { ...

Use jQuery to create a toggle effect with unique attributes and incorporate AJAX functionality

When using this jQuery plugin for creating toggles, I encountered an issue with multiple toggles having the same IDs and classes. This made it difficult to identify a specific toggle to apply auto load ajax when the value changed. I'm wondering how I ...

Having trouble converting JSON into a JavaScript object

I am encountering an issue with my HTML box: <span>Select department</span><span> <select id="department" onchange="EnableSlaveSelectBox(this)" data-slaveelaments='{"a": 1, "b": "2& ...

Steps to create an instance method that only accepts the name of another instance method

I am looking to enhance an object by adding a method that specifically accepts the name of another method within the object. How can I achieve this in a way that dynamically narrows down the accepted names of methods, without hardcoding them? Let's t ...

Click on the social media icon to access the link

Recently, I created a social media icon list for my website but I'm struggling to figure out how to add clickable links to them. I attempted using the "a" tag, but it's not functioning as expected: <div class="leftside"> <ul class= ...

Enhancing images by creating clickable sections in a more organized and efficient manner

Are there any other methods to make parts of an image clickable in a more organized way, aside from using the coordinates method or directly embedding images from Photoshop? <script> new el_teacher = ["candice","john"]; $(".teacher1").mouseenter(fu ...

Update the content retrieved through ajax periodically

Looking to set up a periodic update for this ajax fetch function, say every 10 seconds. I've tried a few approaches but none seem to work as expected. That's why I'm reaching out here for help. So, any idea how I can refresh the content ev ...

Issue encountered when upgrading from Angular 4 to Angular 5: Module '@angular/router' is not found

I recently made the switch from angular 2 to angular 5. However, after the upgrade, I encountered some errors in my ts file. Should I remove @angular/core and @angular/router in angular 5? Here is a snippet of my package.json post-upgrade. Below are the de ...

The Ajax request is exceeding its limits

$(function(){ var imgClass = $('.caruselWrap').find('img'); imgClass.eq(1).addClass('pro'); var hasPro = $('.caruselWrap').find('img.pro'); var count = 3; // "position" of images, security for not breakin ...

Identifying when a system window covers an iframe

After watching a fascinating YouTube video (https://www.youtube.com/watch?v=TzPq5_kCfow), I became intrigued by how certain features demonstrated in the video could be implemented using JavaScript. One specific question that arose for me was how one can d ...

Assign value to twig variable using JavaScript in Symfony version 3.4

Hello everyone, I am currently working on a form that is functioning well. However, I am facing an issue with setting the localization of a place manually using latitude and longitude values. To address this, I decided to create a map with a draggable mark ...

"What is the best way to enforce a mandatory textbox in an alertify prompt using the HTML 5 required

Currently, I am implementing jQuery alertify prompt which can be found at Is there a method to require the textbox by setting attributes directly? Appreciate your assistance! ...