I am curious to see the number of people who have made their selection

I am currently using JavaScript to alter the text value from "select" to "selected".

My next step is to include the selected text in a cart. Can you please provide some guidance? Thank you in advance.

PHP CODE :

<a class='btn slct' href='javascript:void(0)' >Select</a>

Javascript Code :

<script>

$(document).ready(function() {

 $('.slct').click(function() {
$(this).text($(this).text() == 'Select' ? 'Selected' : 'Select');


        });
    });

</script>

Answer №1

$('.btn').click(function(){

    var linkText = $(this).val();
    if(linkText === 'Select'){
        $(this).html('Selected');
   }
});

Perhaps this solution could help address the issue you are facing.

Answer №2

employ

$(this).val($(this).text() == 'Choose' ? 'Chosen' : 'Select');

as an alternative to

$(this).text($(this).text() == 'Choose' ? 'Chosen' : 'Select');

Answer №3

      $(document).ready(function() {
      $('.slct').click(function() {
       var value = [];
       var text = [];
            $(".slct:checked").each(function() {
                value.push(this.value);
                text.push('Selected');
            });

    $.ajax({
    type:"POST",
    url: 'edit.php',
    data: "value ="+ value+"&text="+text ,
    dataType: 'text',
    async: false,
    cache: false,
    success: function ( result )  {
        window.location.reload();
    }
    });
       });
     });

customize the checkbox name to suit your needs.

  $('input[name="checkboxname"]:checked').each(function() {
   $(this).val($(this).text() == 'Select' ? 'Selected' : 'Select');
   $(this).html('Selected');
  });

this piece of code calculates the total number of checkboxes checked.

$('.slct').click(function () {
var check = $('.slct').find('input[type=checkbox]:checked"]').length;
alert(check);
return false;
}):

This alternative method can also be utilized.

var check = $('.slct').find('input[type="checkbox"]:checked').length;
alert(check);

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

Implementing Jquery to Identify the Matching Indices of Two Arrays

I need to find the indices of similar values in array1 and array2, and then save them in a variable named stored_index. array1 = ["50","51","52","53","54","55","56","57","58","59"]; array2 = ["59","55","51"]; The desired result for stored_index is: sto ...

Trouble with uploading images through multer is causing issues

When setting up multer, I followed this configuration let multer = require('multer'); let apiRoutes = express.Router(); let UPLOAD_PATH = '../uploads'; let storage = multer.diskStorage({ destination: (req, file, cb) => { ...

What could be the reason behind the success of my API call in Chrome while encountering failure when implemented in my

I'm attempting to access the Binance API in order to obtain the current price of Litecoin (LTC) in Bitcoin (BTC). For this purpose, I have tested the following URL on my web browser: "https://api.binance.com/api/v1/ticker/price?symbol=LTCBTC". Now, I ...

Select preselected options in a multi-select dropdown using Knockout.js

I have a select multi that I've bound to a model, and now I want to select some values that were previously selected using a second model. It seems like a simple task, but in Knockout.js it's proving to be more complicated than expected. Here is ...

What should I do when using _.extend() in express - override or add in fields?

When an object is extended by another object with values set for some of the extended fields, will it be rewritten or will the new values be added? For example: const PATCH_REQUEST_SCHEMA = { 'type': 'object', 'title' ...

Div element remains fixed in width while zooming in

I'm encountering an issue with a centered div, where the width is set to 50% and the max-width is set to 100%. When I zoom in, the width remains constant but the height increases. Despite setting the max-width to 100%, why does this occur? And most im ...

The jQuery call to a web service is returning XML data, but the success function is receiving a

I have utilized: [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)] The outcome of my web service call is: <string xmlns="http://tempuri.org/"> [{_pkId:"",_code:"",_message:"The file has been uploaded successfully.",_sta ...

Adding a hash to asset paths in NextJS static builds

After running next build && next export, I receive a directory named out, which is great. When examining the source code, such as in the index.html file, it requests assets from <link rel="preload" href="/_next/static/css/styles.aa216922.chunk. ...

Associate keys with strings and then map them to a specific type of strings in Typescript

I am endeavoring to develop a React component that extends the Octicons icon library available from Github at @githubprimer/octicons-react. One of the components exported by the library is the iconsByName type, which has the following structure: type ico ...

Using Selenium to interact with drop-down lists using div tags instead of select tags

As a newcomer to automated testing using Selenium Web Driver, I am struggling to test drop down lists for the location type without relying on the select command. The element in question is enclosed within a div tag. I attempted sending keys but that meth ...

Error: The function used in Object(...) is not defined properly in the useAutocomplete file at line 241

I am currently working on a ReactJS application that utilizes Material UI components without the use of Redux. Everything is functioning properly in my application, except when I attempt to integrate the Material UI autocomplete feature, it encounters iss ...

Trouble with Sound during Quickblox Webrtc Audio Calls

I am having an issue with my audio calls. When I make a call to another user, everything seems fine except that I cannot hear any sound when speaking into the microphone. I am only interested in making audio calls. The call is initiated by pressing a butt ...

The jquery error NS_ERROR_XPC_BAD_CONVERT_JS is causing issues on Google Chrome while working fine on Firefox

Currently, I am utilizing jQuery to dynamically add fields to a form. These are considered "repeatable" fields since users can click an "add more" button. Here is the code snippet: $(".add-attacker-scores").click(function() { count = count + 1; ...

Checking the efficiency of Graphql API

Currently, I am in the process of optimizing key features within my Node.js API which incorporates GraphQL. This API serves as a proxy, receiving requests from various sources and forwarding them to multiple APIs based on the request. I am interested in ...

Getting the raw exception message in Laravel without any HTML formatting can be accomplished by accessing the `

When interacting with the Laravel backend, I frequently make ajax requests. While processing the request data on the backend, there are instances where exceptions are thrown. By default, Laravel generates HTML pages with exception messages. However, my r ...

Is the callback still triggered even after the off function is called?

Can someone help me with a scenario where despite calling the off on a reference, the callbacks are still being triggered repeatedly? var ref = new Firebase('https://example.firebaseio.com/123456'); for (var n = 0; n < 1024; ++n) { ref.pus ...

Adding multiple elements with varying content to a separate division

I am attempting to combine two div elements into a single div, but I'm encountering difficulties. Despite thoroughly examining my code, everything appears to be correct. Here's what I've tried so far. To assist me in achieving this, I am ut ...

Design a dynamic advertisement page using HTML and Bootstrap to ensure responsiveness

I am currently working on a marketing project where I want to give clients the ability to customize their landing page with image ads in a layout that looks something like this: -------------------------------------------------------------------------- | ...

Can we avoid the error callback of an AJAX request from being triggered once we have aborted the request?

Initially, I encountered a challenge where I needed to find a way to halt an AJAX request automatically if the user decided to navigate away from the page during the request. After some research, I came across this helpful solution on Stack Overflow which ...

Executing AJAX calls within a forEach loop

I'm facing a challenge with a function that carries out a foreach loop on a list of views and needs to make an AJAX request for each view within the loop. Upon receiving the results in the success callback, it checks if a specific ID is returned and, ...