Wie überprüfe ich mit JS oder PHP welche HTML Checkbox in einem Form ausgewählt wurde, bevor es abgesendet wurde?

Wie in der Langen Frage geschrieben, ich suche Code der es mir ermöglicht über Java Skript oder PHP auszuwerten welche Checkbox geklickt wurde.

            <input type="checkbox" class="radio-multichoice" name="abteilung:1">

            <label for="frei" align="center"><strong> Abteilung FF </strong></label><br>

            <input type="checkbox" class="radio-multichoice" name="abteilung:1">

            <label for="workS" align="center"><strong> Abteilung W </strong></label><br>

            <input type="checkbox" class="radio-multichoice" name="abteilung:1">

            <label for="MO" align="center"><strong> Abteilung O </strong></label><br>

Im allgemeinen Nutze ich bereits die Funktion in JS damit der User nur ein Element auswählen kann. Doch nun bräuchte ich eine Direkte Ausgabe je nachdem welches Element ausgewählt wurde. D.h. Ich suche eine Möglichkeit auszuwerten welches angeklickt wurde und dann möchte ich etwas ausführen über if, eles if, else.

Falls es helfen sollte hier habe ich die Begrenzung Methode für das anklicken.

   //Dieser Code überprüft ob drei Elemente ausgewählt wurden. Wenn dies der fall ist dann werden alle weiteren Element Blockiert.

   const groups = [...document.getElementsByClassName("radio-multichoice")].reduce((result, element) => {

 result[element.name] = result[element.name] || [];

 result[element.name].push(element);

 return result;

}, {});

for (const [name, elements] of Object.entries(groups)) {

 const limit = name.split(":")[name.split(":").length-1];

 for(const el of elements) {

  el.addEventListener("change", e => {

   if (elements.filter(x => x.checked).length > limit) {

     e.target.checked = false;

   }

  });

 }

}

Könnte mir dabei jemand Helfen, falls ihr nachfragen habt weil ich es mal wieder nicht richtig erklären konnte stellt bitte eine Nachfrage.

Computer, HTML, Webseite, programmieren, JavaScript, PHP, Webentwicklung
Android Studio: Wieso verändern die Elemente ihre Position?

Hey,

ich habe da ein kleines Problem. Auf dem PC sind alle Elemente dort, wo sie sein sollten, aber wenn ich die App auf dem Handy ausführe, sind die Elemente irgendwie bzw. irgendwo platziert. Kann mir jemand vielleicht sagen, woran es liegen könnte?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/black_shade_1"
  tools:context=".MainActivity">
  <ImageView 
    android:layout_width="152dp"
    android:layout_height="185dp" 
    app:srcCompat="@drawable/iconqrlogo" 
    android:id="@+id/imageView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="32dp"
    app:layout_constraintHorizontal_bias="0.498" />
  <ProgressBar
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:visibility="visible"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    android:layout_marginTop="56dp"
    app:layout_constraintTop_toBottomOf="@+id/imageView" />
  <Button
    android:text="@string/generateButton"
    android:layout_width="250dp"
    android:layout_height="60dp"
    android:id="@+id/generateQrCode"
    app:backgroundTint="@color/yellow"
    android:textColor="#000000"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintHorizontal_bias="0.496"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginBottom="160dp" />
  <Button
    android:text="@string/scanCode"
    android:layout_width="250dp"
    android:layout_height="60dp"
    android:id="@+id/scanQrCode"
    app:backgroundTint="@color/yellow"
    android:textColor="#000000"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/progressBar"
    android:layout_marginTop="48dp"
    app:layout_constraintHorizontal_bias="0.503"
    app:layout_constraintBottom_toTopOf="@+id/generateQrCode"
    app:layout_constraintVertical_bias="0.061" />
</androidx.constraintlayout.widget.ConstraintLayout>
Bild zum Beitrag
Computer, App, programmieren, Java, Android, Android App, Android Studio
Count Sort Funktion geht zu früh aus der Schleife?

Ich möchte ein Programm schreiben, dass ein Array mit Count Sort sortieren soll. Doch habe ich einen Fehler. Meine Eingabe für das unsortierte Array war:

38 38 19 57 0 18 59 27 18 57 19 47 4 2 5 5 1 1 

Aber als Ausgabe bekam ich bloß:

 0 1 1 2 4 5 5 0 0 0 0 0 0 0 0 0 0 0

Für dieses Programm sind besonders 2 Funktionen wichtig und ich denke, dass in einen der Beiden mein Fehler ist. Hier ist meine erste Funktion fürs Zählen:

void count(int input_array[], int len, int count_array[]) 
{
	for (i=0; i < len; i++) 
	{
		count_array[i] = 0;
    }
	for (j=0; j<len;j++) 
	{
		count_array[input_array[j]]++;
    }
}

Meine erste For-schleife soll sagen, dass count_array min. 38 Stellen lang sein soll und soll überall mit 0 initialisierst werden. "len" steht für Länge und ist 38.

Die zweite for-Schleife soll das eigentliche Nachzählen tun. zBs. bei j=1 sollte die for-Schleife also im output_array eine 38 finden. Also soll count_array bei der Stelle 38 um eins erhöhen. Das gleiche mit j=2 usw.

Und meine zweite Funktion soll nun das output Array schreiben, welches richtig sortiert ist. k ist der Index im output_array. k ist der Index. Die erste for-Schleife soll das count_array durchgehen und die zweite for-Schleife soll das schreiben der Zahl so oft wiederholen, wie häufig diese gefunden wurde.

void write_output_array(int output_array[], int len, int count_array[]) 
{
	k=0;
    for (j=0; j < len; j++) 
	{
		for (i=0; i < count_array[j]; i++) 
		{
			output_array[k] = j;
			k++;
		}
	}
}

Hat jemand eine Idee warum write_output_array wohl früher endet als gewollt?

Computer, programmieren, CC, Informatik, C (Programmiersprache), Sortieralgorithmus
Navigation ausklappbar <html/CSS>?

Hallo,

ich möchte eine Navigation bauen, die wenn man hovert noch Unterpunkte anzeigt. Ich habe es so gemacht und komme leider nicht mehr weiter, wenn sich die Navigation ausklappt soll es ganz oben angezeigt werden. Ich habe einen Button unter der Navigation und als ich es selbst versucht hatte, zeigte es mir das Ausgeklappte hinter dem Button.

HTML:

    <header>
        <nav>
            <ul>
                <li><a href="">Hallo</a>
                    <ul>
                        <li><a href="">Hallo</a></li>
                    </ul>
                </li>
                <li><a href="">Hallo</a>
                    <ul>
                        <li><a href="">Hallo</a></li>
                        <li><a href="">Hallo</a></li>
                    </ul>
                </li>
                <li><a href="">Hallo</a></li>
                <li><a href="">Hallo</a></li>
                <li><a href="">Hallo</a></li>
                <li><a href="">Hallo</a></li>
            </ul>
        </nav>


    </header>

CSS:

header ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: darkblue;
  height: 1.5cm;
  
}


header li {
  float: left;
}


header li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}


header li a:hover:not(.active) {
  background-color: rgb(195, 251, 255);
  color: black;
  height: 29px;
  font-weight: bolder;
}


header .active {
  background-color: #00e1ff;
  height: 21px;
  height: 29px;
  font-weight: bolder;
  color: darkblue;
}

Ich hoffe, dass mir irgendjemand helfen

Danke im voraus

Ps.: Das "Hallo" ist ein Platzhalter.

HTML, Programmierer, programmieren, CSS, Programmiersprache, Webdesign, Visual Studio Code

Meistgelesene Beiträge zum Thema Programmieren