function add() with select, but i cant select the same number twice

Mohammed Salim

I cant select the same number twice, I am trying to use select to input the number and use the function to add them together.

<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </script>

<script>
  const firstFunct = (() => {
    let counter = 0;
    return () => {
      counter += +document.getElementById("mySelect").value;
      document.getElementById("Group 1 score").innerHTML = counter;
      if ((counter) >= 54) {
        document.body.innerHTML = "<p class='Group'>Group 1 Win</p><p onClick='location.reload()'                 class='Again'>Again</p>";
      }
    };
  })(); 
</script>
<form>
  <select id="mySelect" onchange="firstFunct()">
    <option value="" disabled selected style="display:none;">+</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>12</option>
    <option>14</option>
    <option>16</option>
    <option value="1">1</option>
    <option value="54">win</option>
  </select>
</form>
<p id="Group 1 score" style="font-size: 75px;">0</p>

MadaZZ

Change the firstFunct, as given below. The added line of code clears the last selected value after it has been added to the counter. That allows you to select the same value repetitively.

<script>
      const firstFunct = (() => {
        let counter = 0;
        return () => {
          counter += +document.getElementById("mySelect").value;
          document.getElementById("mySelect").value = null; //**this would clear the last selected value 
          document.getElementById("Group 1 score").innerHTML = counter;
          if ((counter) >= 54) {
            document.body.innerHTML = "<p class='Group'>Group 1 Win</p><p onClick='location.reload()'                 class='Again'>Again</p>";
          }
        };
      })(); 
    </script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Alternative to calling same function twice on a select query

How to use function result twice in the same select

SQL avoid calling same function twice in select statement

Cant call same function twice in same php page

I got a object object and cant select the items

Can't select same row twice in SwiftUI

How to select the same column twice with different order

SQL: Select the same column twice in one query?

How to select twice the same column on join query?

SELECT or JOIN using same column twice

Select same row twice, and make the copy immutable

SELECT from a table twice in the same query

C# - LINQ Select() calls function twice

I need to select same column name twice having deferent values based on another table

React : why I have to click twice on the same option to set in select box

Select Column Data from Database (Cant be converted to number?)

Cant add collection_select while using materialize rails 4.2

Cant select elements on Webpage

i Cant Select file in my own browser in android

Select twice in another select statement

MySQL Query from one table - Select same field twice

Select all rows with values that appear twice by the same customer?

How to Select same column in 1 table twice in mysql

How to optimize this SQL query which select from the same table twice

MySQL get back the same value twice from a SELECT DISTINCT

sqlite3: how to select same row twice when there is a match?

SQL - Select rows from same table twice without using UNION

SQL Select - Return same column twice based on IDs in another table

Same column as twice in SQL server SELECT query with Group BY, ORDER BY clauses