Home > OS >  How to count a number of a certain option was clicked?
How to count a number of a certain option was clicked?

Time:09-27

We have a dropdown one that allow users to select car Make, and another to select car Model

<select  name="make">

   <option value="">-- Car Make --</option>
   <option value="Acura">Acura</option>
   <option value="Acura">Audi</option>
   <option value="BMW">BMW</option>
   <option value="BMW">Mercedes Benz</option>

</select>

When Audi is chosen..

<select  name="model">
    <option value="">-- Model --</option>
    <option value="A1">A1</option>
    <option value="A3">A3</option>
    <option value="A4">A4</option>
    <option value="A5">A5</option>..
</select>

These values are in a table in the database and when the options are populated when Make is selected the Model gets populated.

We want to count the number of times "BMW" for example was selected using jQuery. How can we achieve this? Or "Audi A1".

Specifying the value of the option and then counting will not work as we have a lot of data, we need to count how many times each Make or model was clicked/selected and save the data as a number in the database later.

How can we do the count?

CodePudding user response:

You can have some event onClick on these component, and when someone clicks you send the ID that this person just click to your DB.

so if you wanna count how many clicked on some especific car, you just select on your database, like:

Selec Count(*) from clickedcars where carid="A1"

  • Related