JavaScript Show & Hide Controls

Ein zusätzliches Formularelement ein- und ausschalten über eine Checkbox.

StyleSheet Lösung

show_hide.htm HTML (609 bytes) 19.10.2021 23:52
<!DOCTYPE html >
<html>
  <head>
    <title>Show / Hide</title>
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: " />
    <style type="text/css">
      .toggle-content {
    display: none;
  }
  #toggle:checked ~ .toggle-content {
    display: block;
  }
    </style>
  </head>
  <body>
    <form><input type="checkbox" id="toggle" /><label for="toggle">alternativer Text</label><label class="toggle-content">Label:<input type="email" /></label></form>
  </body>
</html>

JavaScript Lösung


show_hide.htm HTML (725 bytes) 19.10.2021 23:52
<!DOCTYPE html >
<html>
  <head>
    <title>Show/Hide Div Content Demo</title>
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: " />
  </head>
  <body>
    <form><input type="checkbox" name="checkbox" id="checkbox_id" value="true" onchange="document.getElementById('toggle_id').style.display = this.checked ? 'block' : 'none';" /><label for="checkbox_id">alternativer Text</label><br />
      <div id="toggle_id" style="display:none;"><label for="textbox">Label:</label><input type="text" name="textbox" id="textbox" /></div>
    </form>
  </body>
</html>

Author: , published: , last modified:

Kontakt

Udo Schmal

Udo Schmal
Softwareentwickler
Olvengraben 41
47608 Geldern
Nordrhein-Westfalen
Germany





+49 2831 9776557
+49 1575 0663676
+49 2831 1328709
SMS
WhatsApp

Google Maps Profile
Instagram Profile
vCard 3.0

Service Infos

CMS Info Product Name:
UDOs Webserver
Version:
0.5.0.122
Description:
All in one Webserver
Copyright:
Udo Schmal
Compilation:
Fri, 14. Jan 2022 21:55:59
Development Info Compiler:
Free Pascal FPC 3.3.1
compiled for:
OS:Linux, CPU:x86_64
System Info OS:
Ubuntu 20.04.3 LTS (Focal Fossa)
Hardware Info Model:
Hewlett-Packard HP Pavilion dv7 Notebook PC
CPU Name:
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
CPU Type:
x86_64, 1 physical CPU(s), 2 Core(s), 4 logical CPU(s), 1232.209 MHz