[JS] Radiobuttons

Pagina: 1
Acties:

  • Guillome
  • Registratie: Januari 2001
  • Niet online
Hai.
Ik heb 2 radiobuttons:
code:
1
2
3
4
5
6
7
<INPUT NAME=geslacht TYPE="radio" ID="man"
onkeypress="checkkey(window.event.keyCode);" value=m>
<font class=normaltext>Man</font>

<INPUT NAME=geslacht TYPE="radio" ID="vrouw"
onkeypress="checkkey(window.event.keyCode);" value=v>
<font class=normaltext>Vrouw</font>

Hoe kan ik nou in een JS scriptje controleren of en eigelijk ook welke er is geselecteerd?

Bij voorbaat dank.

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


  • Guillome
  • Registratie: Januari 2001
  • Niet online
Schiet nou ohop!
Ik moet het project morgenvroeg inleveren ! :P :)
Echt waar

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


  • Thijsmans
  • Registratie: Juli 2001
  • Laatst online: 13:22

Thijsmans

⭐⭐⭐⭐⭐ (5/5)

Het valt dus eigenlijk onder huiswerk, maar goed.
code:
1
2
3
4
5
<form name=geslachtsformulier>
 <input type=radio name=geslacht value="man">
 <input type=radio name=geslacht value="vrouw">
 <input type=button onClick=alert(document.geslachtsformulier.geslacht.value)>
</form>

das alles wat je nodig hebt om een geslacht te bepalen (nu is het alleen een alert functie, maak je eigen functie voor iets anders zou ik zeggen)

Privacy-adepten vinden op AVGtekst.nl de Nederlandse AVG-tekst voorzien van uitspraken en besluiten.


  • Guillome
  • Registratie: Januari 2001
  • Niet online
Werkt niet ;(
Hij zegd dan Undefined

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Op donderdag 10 januari 2002 13:35 schreef XLerator het volgende:
Schiet nou ohop!
Ik moet het project morgenvroeg inleveren ! :P :)
Echt waar
Goh ... wel 3 hele minuten gewacht....

Hoe hou je het uit!!!!

|:( |:(

Programmer - an organism that turns coffee into software.


  • Guillome
  • Registratie: Januari 2001
  • Niet online
Op donderdag 10 januari 2002 13:56 schreef LuCarD het volgende:

[..]

Goh ... wel 3 hele minuten gewacht....

Hoe hou je het uit!!!!

|:( |:(
Jeeeeeeemig, doe rustig man
Was een grapje, weet je wel wat die smilies betekenen???? :o

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


Verwijderd

Haastige spoed is zelden goed, maar vooruit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
<script language="JavaScript">
<!--
function controleer () {
if (document.forms[0].geslacht[0].checked) {
alert("man");
}
if (document.forms[0].geslacht[1].checked) {
alert("vrouw");
}
}
//-->
</script>

Verwijderd

Op donderdag 10 januari 2002 15:02 schreef pbirkoff het volgende:
code:
1
2
3
4
5
6
7
8
9
10
11
12
<script language="JavaScript">
<!--
function controleer () {
if (document.forms[0].geslacht[0].checked) {
alert("man");
}
if (document.forms[0].geslacht[1].checked) {
alert("vrouw");
}
}
//-->
</script>
En als je de volgende keer 30 radiobuttons hebt ?? :P
Maar dit klopt iig wel..

  • Guillome
  • Registratie: Januari 2001
  • Niet online
Nee maar ik bedoel, je geeft 4 radiobuttons dezelfde naam, dan is dat 1 groep.
In PHP kan je dan die naam.value opvragen en dan krijg je de value van de radiobutton in die groep die geselecteerd is.
Kan dat niet in JS?

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


  • OxiMoron
  • Registratie: November 2001
  • Laatst online: 27-06 10:54
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
<head>
</head>
<script>
    function Check()
    {
        for(i=0;i<document.iets.geslacht.length;i++)
            if (document.iets.geslacht[i].checked==true)
                alert(document.iets.geslacht[i].value);
    }
</script>
<body>
<form name="iets">
<input type=radio name=geslacht value="man">Man
<input type=radio name=geslacht value="vrouw">Vrouw
</form>
<br>
<br>
<a href="#" onclick="Check();">Check it</a>
</body>
</html>

Albert Einstein: A question that sometime drives me hazy: Am I or are the others crazy?

Pagina: 1