Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  197] [ 7]  / answers: 1 / hits: 16080  / 10 Years ago, sun, december 28, 2014, 12:00:00

I have write some simple code which would make input field enabled and disabled on button click but it is not responding.
please help me...!!!



<html>
<head>
<script type=text/javascript>
function toggleEnable(el1, el2) {
document.getElementByID(el1).disabled = true;
document.getElementByID(el2).disabled = true;
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td><input id=input1 class=myText type=text placeholder=Row 1 /></td>
<td><input id=input2 class=myText type=text placeholder=Row 1 /></td>
<td><button onclick=toggleEnable('input1','input2')> Enable/Disable </button></td>
</tr>
<tr>
<td><input id=input3 class=myText type=text placeholder=Row 3 /></td>
<td><input id=input4 class=myText type=text placeholder=Row 4 /></td>
<td><button onclick=toggleEnable('input3','input4')> Enable/Disable </button></td>
</tr>
</table>
</form>
</body>
</html>

More From » css

 Answers
3

Your buttons are submitting the form the are in, to not submit the form you'll have to use a type=button button, also you've spelt getElementByID incorrectly its getElementById



<form>
<table>
<tr>
<td><input id=input1 class=myText type=text placeholder=Row 1 /></td>
<td><input id=input2 class=myText type=text placeholder=Row 1 /></td>
<td><button type=button onclick=toggleEnable('input1','input2')> Enable/Disable </button></td>
</tr>
<tr>
<td><input id=input3 class=myText type=text placeholder=Row 3 /></td>
<td><input id=input4 class=myText type=text placeholder=Row 4 /></td>
<td><button type=button onclick=toggleEnable('input3','input4')> Enable/Disable </button></td>
</tr>
</table>
</form>




    function toggleEnable(el1, el2) {
document.getElementById(el1).disabled = true;
document.getElementById(el2).disabled = true;
}


http://jsfiddle.net/mowglisanu/aam7jg9t/


[#68368] Wednesday, December 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
draven

Total Points: 641
Total Questions: 101
Total Answers: 110

Location: Nicaragua
Member since Mon, Sep 26, 2022
2 Years ago
draven questions
Tue, Apr 12, 22, 00:00, 2 Years ago
Thu, Feb 17, 22, 00:00, 2 Years ago
Tue, Nov 30, 21, 00:00, 3 Years ago
Tue, Oct 19, 21, 00:00, 3 Years ago
;