Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Javascript: Checkboxen automatisch abhaken

Empfohlene Antworten

Veröffentlicht

Sehr dringend, bitte helft mir!

Folgendes Problem:

Ich möchte per JavaScript automatisch mehrere Checkboxen abhaken lassen.

Wichtig dabei: die Bennenung der Checkboxen muss [] beinhalten, zwecks Array.

Ich wäre sehr dankbar, wenn mir jemand bei der Lösung helfen könnte.

Hier ein fehlerhafter Beispielcode:


<script language="JavaScript">

	<!-- Begin

		var checkflag = "false";

		function checkall(anzahlboxen)

		{

			if (checkflag == "false")

			{

				for (i = 0; i <= anzahlboxen; i++)

				{

					document.formular_anfrage.checked_email[i].checked = true;

				}

				checkflag = "true";

				return "keine selektieren";

			}

			else

			{

				for (i = 0; i <= anzahlboxen; i++)

				{

					document.formular_anfrage.checked_email[i].checked = false;

				}

				checkflag = "false";

				return "alle selektieren";

			}

		}

	//  End -->

</script>


<form name="formular_anfrage" method="post" ACTION="">

<table>

	<tr>

		<td class=\"liste\" align=\"center\" valign=\"middle\"> 

			<input type="checkbox" name="checked_email[]" value="1|1" class="checkbox">

		</td>

		<td class=\"liste\" align=\"center\" valign=\"middle\"> 

			<input type="checkbox" name="checked_email[]" value="2|2" class="checkbox">

		</td>

		<td class=\"liste\" align=\"center\" valign=\"middle\"> 

			<input type="checkbox" name="checked_email[]" value="3|3" class="checkbox">

		</td>

		<td class=\"liste\" align=\"center\" valign=\"middle\"> 

			<input type="checkbox" name="checked_email[]" value="4|5" class="checkbox">

		</td>

	</tr>

</table>

</form>

<br><br>

<input type="button" name="check_all_companies" value="alle selektieren" onclick="this.value=checkall(3)">

Hi

in meinem Beispiel, wird von einer Checkbox aus (mthis) alle anderen Checkboxen angehakt.


<script language=Javascript>
function SetAllCheckBoxes(FormName, FieldName, mthis)
{
CheckValue = true;

if (mthis.checked) CheckValue=true;
else CheckValue=false;

if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes) return;

var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes) objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
</script>

<form name=rex_file_list action=index.php method=post>
<input type="checkbox" name="selectedmedia[]" value="7">
<input type="checkbox" name="selectedmedia[]" value="10">
<input type="checkbox" name="selectedmedia[]" value="14">
</form>

<input type=checkbox name=checkie value=0 onClick="SetAllCheckBoxes('rex_file_list','selectedmedia[]',this)">
[/PHP]

Gruß,

Markus

Danke Markus, klappt wunderbar .... und schön kompakt!

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.