The JavaScript code appears to be missing or failing to execute on the website

Encountering a console error while trying to integrate jQuery into my website. The JavaScript file is throwing an error in the console that says:

Uncaught ReferenceError: $ is not defined catergory.js:1

Even after following the suggested steps in this answer, the issue persists.

The following JavaScript code appears to be ineffective.

<html><head>

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <link rel="stylesheet" href="css-js/design.css">
    <link rel="stylesheet" href="css-js/fly-in-animations.css">
    <link rel="stylesheet" href="css-js/design2.css">
    <script src="css-js/category.js"></script>
    <meta charset="utf-8">
    <title>PC Tech - Products</title>
</head>
<div class="category">
        <label class="pcpartstext" for="pcparts">Choose a category:</label>
            <select name="pcparts" id="pcparts">
                <option selected disabled>Choose One</option>
                    <optgroup label="Computer Hardware">
                      <option value="cpu">Central Processing Unit (CPU)</option>
                      <option value="cpucooler">CPU Cooler</option>
                      <option value="mobo">Motherboard</option>
                      <option value="ram">Random Access Memory (RAM)</option>
                      <option value="storage">Storage (HDDs/SSDs)</option>
                      <option value="gpu">Video Cards (GPU)</option>
                      <option value="psu">Power Supply (PSU)</option>
                      <option value="cases">Case/Chassis</option>
                    </optgroup>

                <optgroup label="Computer Accessories">
                  <option value="monitor">Monitors</option>
                  <option value="keyboardmousepad">Keyboard, Mouse & Mousepads</option>
                  <option value="speakerandheadset">Speakers & Headsets</option>
                </optgroup>
            </select>
    </div>

    <div class="product-info">

    </div>
javascript
$('#pcparts').on('change', function() {
  if (this.value === 'cpu') {
    $('.product-info').html('<div class="details"><p class="info">CPU product info</p><button class="purchase">Purchase</button><div>')
  } else if (this.value === 'cpucooler') {
    $('.product-info').html('<div class="details"><p class="info">CPU Cooler product info</p><button class="purchase">Purchase</button><div>')
  }
});

Answer №1

It is important to expand the options available for each selection.

$('#pcparts').on('change', function() {
  if (this.value === 'cpu') {
    $('.prodct-info').html('<div class="details"><p class="info">CPU product info</p><button class="purchase">Purchase</button><div>')
  } else if (this.value === 'cpucooler') {
    $('.prodct-info').html('<div class="details"><p class="info">CPU Cooler product info</p><button class="purchase">Purchase</button><div>')
  }
else if (this.value === 'mobo') {
    $('.prodct-info').html('<div class="details"><p class="info">CPU product info</p><button class="purchase">Purchase mobo</button><div>')
  }
//more conditions can be added here
});

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

There are no connection events being triggered - using Mongoose version 4.7.1 with Express

My current struggle involves establishing a connection from my express app to MongoDB via Mongoose. Despite the simplicity of the setup, which is as basic as it gets: var mongoose = require('mongoose'); mongoose.connect('mongodb://localhos ...

Utilize ngModel in conjunction with the contenteditable attribute

I am trying to bind a model with a tag that has contenteditable=true However, it seems like ngModel only functions with input, textarea or select elements: https://docs.angularjs.org/api/ng/directive/ngModel This is why the following code does not work ...

Ways to analyze users who have clicked a button

After a user registers, they are automatically taken to /proto where they can view a list of animals available for adoption. However, the challenge lies in identifying the specific user who clicked the button (as this information must be associated with th ...

Is it possible to retrieve information from a MySQL database by utilizing Bootstrap and Ajax with the selected ID?

I am currently working on two php pages. The first php page contains a table with records that can be edited using a Bootstrap Modal, while the second php page processes updates to the MySQL database. Below is the code for the first php page (edit_account ...

Widget remains static until job triggers data refresh, preventing CSS transition initialization

I am struggling with the html/coffee/scss aspects, although I'm comfortable with Ruby. On my website, I have implemented a hotlist widget sourced from this link: https://gist.github.com/andre-morassut/8705385. While it functions properly, I encounter ...

Experience the dynamic expansion of a droppable div as you elegantly drop an element within

When the questions "question1" and "question2" are dragged into "questionslots," I want the "questionSlots" div to expand its size dynamically when the second question is dropped into it. This means that both questions should be accommodated and visible wi ...

Angular directive dilemma

Angular is causing some issues for me as I am a beginner in using it. Below is the JSON data that I am dealing with: [ { "name":"43", "values":{ "audio":"Audio Only", "low":"Low Bandwidth", "medium":"Medium Bandw ...

Exploring the Wonderful World of Styled Components

I have a query regarding styled components and how they interact when one is referenced within another. While I've looked at the official documentation with the Link example, I'm still unclear on the exact behavior when one styled component refe ...

Alter the color of H3 when clicked and then gently fade it back

Is it possible to create a button on the top of my webpage that scrolls to a specific DIV when clicked, and also have it change the color of an h3 element once it has scrolled to it? This effect is similar to how Facebook highlights notifications. This is ...

Tips on creating animations for a background with a value of 2 using CSS3

Hey everyone, I'm currently working with this CSS style: body { width:100%; height:100%; background:#fff; background-image: url(bg.png), url(clouds.png); background-repeat: repeat; font-family: tahoma; font-size: 14px; ...

Strange CSS Problem: Button dysfunction in displays sized 13 inches or 15 inches

I have made a landing page using the latest version of bootstrap. However, I am encountering an odd issue where the success button is not clickable on certain devices such as 13-inch and 15-inch laptops and desktops. You can find the URL for the landing p ...

The Vue component fails to respond to updates in plugin data

I am currently working on implementing a feature where a component reacts to data changes in a custom Vue plugin. To achieve this, the plugin creates a new instance of a Vue object in its constructor: this._vm = new Vue({ data: { obj: null, stat ...

Translate CSS into JavaScript while maintaining selector understanding

I am interested in developing a tool that can read a .css file and generate a function that will accept an array of class names as input and output the corresponding styles for an element with those classes, represented as a JavaScript object. This tool wo ...

Steps for positioning an item above CardActionArea

I would like to figure out how to position an object above the CardActionArea. For example, if I have a button on top of the CardActionArea and click on that button, both the CardAction and Button actions will be triggered simultaneously. I want it so that ...

Map image showing only the tile layer in the top corner

My current project involves utilizing Ionic 5 and Vue.js. One of the screens in my project features a leaflet map that needs to cover most of the screen space. To implement this, I have integrated the Leaflet library for vue into my code. Here is a snippe ...

What is the total amount within a specified date range when retrieved as JSON?

Consider the following JSON structure: { "timesheets": [ { "user": { "username": "erik", "first_name": "Erik", }, &q ...

How to disable scrolling for React components with CSS styling

When incorporating a React component into my HTML, I follow this pattern: <html> <body> <div id=app>${appHtml}</div> <script src="/bundle.js"></script> </body> </html> Within my application, th ...

A step-by-step guide on incorporating a dynamic data series into a line chart using the powerful tool

The data retrieved from a webservice is processed using the BindTrend method and then converted to a JSON object before being applied to the chart. The code for this process is as follows: var plot; var itemdata = []; var chart; var data = [] ...

What is the best way to include a check mark icon using MUI or Tailwind CSS for every item selected in a dropdown menu?

I need help with adding a small check/tick icon next to the selected value, for example: Operations ✓ when the user chooses operations in the TopicList dropdown list. The TopicList is a class component used to retrieve data from the database which incl ...

What is the best way to make a CSS change triggered by a onScroll() event stay in place permanently?

I need a div element to be displayed as a "scroll back to top" button on my webpage when the user has scrolled past a certain point. To achieve this, I am using the JavaScript code provided below: $(document).ready(function() { $(window).scroll(functio ...