Javascript issue with if statement not functioning properly

If you go to the website here and attempt to click on the voting arrows, you'll encounter the issue I'm facing. Contrasting this with the homepage where clicking on the logo allows you to vote. The arrows change their appearance based on the vote, with the help of the in_array() function which determines the user's vote and displays the corresponding icon correctly. Everything works smoothly on the linked submission page. However, when trying to click on the links, it always defaults to the else statement in the Javascript function provided below:

I am only presenting the function for liking as I'm encountering a similar problem with disliking.

function getVote(filename, num, idnum, user)
  {
    var like = document.getElementById('like_arrow' + num);
    var dislike = document.getElementById('dislike_arrow' + num);

  if (like.src.indexOf('../vote_triangle.png')!=-1 && dislike.src.indexOf('../vote_triangle_flip.png')!=-1) {
   like.src = '../vote_triangle_like.png';

         (AJAX to alter rating here)

  } else if (like.src.indexOf('../vote_triangle.png') != -1) {
   like.src = '../vote_triangle_like.png';
   dislike.src = '../vote_triangle_flip.png';

         (AJAX to alter rating here)

  } else {
   like.src = '../vote_triangle.png'; // Always defaults to this

         (AJAX to alter rating here)

  }

}

In case you're curious, the num variable is used on the front page to differentiate between submissions by incrementing each time. In this case, I have left that value blank in the function so it shouldn't be causing any issues. It could potentially be my problem, but I am unable to identify how.

Thank you!

Answer №1

like.src does not include ..\. You can try removing that part to simplify it.

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

How can you retrieve a value from a JavaScript closure function?

I'm struggling with getting a value from a closure function in Javascript. In my initial attempt, I placed the return statement inside the inner function, but it was not effective. Then, I tried moving the return statement to the outer function, howev ...

Find the names of keys which have a value of true in reactjs

Greetings, I have a JSON file that contains information about different components. I am trying to extract only the Dashboard and Datatable sections where the "visible" attribute is set to true. { "MTs": { "Dashboard": { "id": 1, "visible ...

Asynchronous setTimeout for server-side operations

I am currently facing an issue with my web server. Whenever a request is made, the server initiates a phone call, waits for 3 seconds, and then checks if the call is still ongoing. I have utilized setTimeout to achieve this functionality, but it seems to b ...

The value of YOUR_VARIABLE in the Node.js process environment appears to be undefined

Having trouble hiding a discord token for my bot, even though I believe dotenv is set up correctly. However, all I keep getting back is undefined. I've gone as far as using nodemon to refresh the server when making changes, but the issue persists. Co ...

Updating the Navbar in React Routing does not happen automatically, but it does refresh when the page is refreshed

Currently, I am using vanilla React with React-Router for my project. One of the issues I am facing is detecting whether a user on the page has a token, indicating their logged-in status. While setting up routes for Login/Register/Logout functionalities, ...

The jQuery .on('click') event is only functioning properly the first time it is clicked

Recently, I encountered a peculiar issue with an on-click event that seems to work only once. The intended functionality is to toggle the .p-active class, but instead, it only adds it. The problem arises from dynamically added content post-click using lig ...

Tips for customizing the to_json functionality in Rails 4 by incorporating a dynamic attribute

My goal is to include a dynamic attribute in my controller alongside the other data stored in the @events instance variable. I've researched and attempted methods like @events.attributes.merge(appointment: true) appointment = true is the specific pr ...

Error when using the array.filter() method with polygons

I am working with an array named coordinate that contains latitude and longitude values for a polygon. I am trying to find the maximum and minimum latitude/longitude stored in this array. My approach involves using the array.filter() method to filter the ...

What is the most efficient method to generate an array where the initial word is located at index 0, while the remaining words are located at index

Seeking advice on how to optimize and speed up the following code. Sample Input: "hello, my name is Alice" Expected Output: ["hello,", "my name is Alice"] Current code implementation: function extractInfo(inputString) { var words = inputString. ...

Creating a dual-column checkbox design with CSS only

I'm working with a dynamically generated form element that can only be styled using CSS. I need help achieving a specific layout without making any HTML changes, except for the classes. The "element" and "formField" classes are common and cannot be mo ...

Tips for resolving the issue of data.map not being recognized as a function in the API

I am attempting to retrieve and display data from an API. Despite my efforts, I am unable to successfully showcase the data. PokemonSpecies.js import React from "react"; // import Loader from "./Loader"; import { Card, Col } from "react-bootstrap"; imp ...

What is the best way to iterate through the split result array of a multiline string in order to reformat specific lines and newlines?

I have a string of data with line breaks in the middle. For instance: "Product Name \n Product Color \n Product Quantity \n Product Location \n Product Size \n Product Power" The number of elements in the string could be ...

The onmessage event in the websocket client seems to be malfunctioning and is not triggering

In my implementation using node.js, I have set up a websocket server and client. The handshake process between the server and client appears as follows: Request URL: ws://localhost:8015/ Request Method: GET Status Code: 101 Switching Protocols Request ...

What is the best way to locate the relative xpath of an element that I click on a webpage using Javascript?

Is there a way to use JavaScript in order to retrieve the relative XPath of any element that I click on my page? The code provided doesn't seem to be working as expected. How can I modify it to achieve the desired result? function findElementXPath( ...

Attempting to make my initial Ajax program function, but unfortunately, no dynamic actions are being generated

I'm currently trying to replicate the functionality of this example from a reliable source, but I am facing an issue where no suggestions are being added when typing in a name. nameguess.html <!DOCTYPE html> <html lang="en-ca"> <head& ...

Is it possible to pass the button id to a Bootstrap modal when clicked?

In my Laravel project, I have a list of user details retrieved from the database. Each record has an edit and remove button at the end. When clicking the remove button, the specific record is deleted. However, when I added a modal that appears after clicki ...

unable to get highcharts to redraw and reflow properly

I am currently working on creating a dynamic page that can display between 1-4 graphs. These graphs need to be able to resize when added or removed from the page. However, I have encountered a major issue with resizing the graphs after resizing the contain ...

Is there a way to update Checkbox changes within a Datagrid without selecting the entire row?

My Table Cell Checkbox Behavior Issue: Within a table cell, I have a checkbox that changes upon clicking it. However, the change only occurs the first time. Subsequent clicks on the same checkbox do not trigger any change until I click outside the cell. T ...

Is it necessary to include `load` events if scripts are placed at the bottom of the body?

Is it necessary to enclose code in the following: window.addEventListener('load', () => {}) If your scripts are already loaded at the end of the body tag? Wouldn't this ensure that the DOM has been fully loaded, rendering a load event li ...

How can I modify the fill color of a Cell when hovering over a Bar Chart in Recharts?

I have been rendering the chart in the following manner: <BarChart width={868} height={40} data={data} margin={{top:0, bottom: 10, left:0, right:0}} barSize={5}> <Tooltip labelStyle={{ textAlign: &apo ...