Disable all textboxes

Status
Niet open voor verdere reacties.

Seantf

Gebruiker
Lid geworden
23 apr 2013
Berichten
140
Hey ik wil graag dat alle textboxes gedisabled worden als ik op een knop klik alleen de volgende code werkt niet.

Ik denk dat dit komt doordat ik 2x dezelfde id gebruik maar ik heb geen idee hoe ik dit anders kan oplossen?

Alvast bedankt.

index.php
Code:
<!DOCTYPE html>
<html>
<body>

Name: <input type="text" id="myText">
Leeftijd: <input type="text" id="myText">


<p>Click the button to disable the text field.</p>

<button onclick="myFunction()">Disable Text field</button>
<button onclick="myFunction1()">Disable Text field</button>

<script>
function myFunction() {
    document.getElementById("myText").disabled = true;
}
</script>

<script>
function myFunction1() {
    document.getElementById("myText").disabled = false;
}
</script>

</body>
</html>
 
Zet je script in de head sectie
Code:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(inputID) {
  document.getElementById(inputID).disabled = true;
}
</script>
</head>
<body>
<form>
Name: <input type="text" id="myText1">
Age : <input type="text" id="myText2">
</form>
<p>Click the button to disable the text field.</p>
<button onclick="myFunction('myText1')">Disable Text field 1</button>
<button onclick="myFunction('myText2')">Disable Text field 2</button>
</body>
</html>

*** aanvulling: een id mag maar 1x in een pagina voorkomen. Classes mogen meerdere keren voorkomen.
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan