1

This is a function that is part of a larger website I am designing. In a general sense I am trying to perform a Javascript function that will un-disable the disabled input HTML boxes from the click of a 'yes" button.

After clicking the "yes" button it seems it is not working.

Here is my code.

<html>
    <head>
        <script language="javascript" type="text/javascript">
          function myFunction() {
          document.getElementById("first").disabled = false;
        }
</script>


 </head>
 <body>
      Perform Operation?: <br>
                <button onClick=myFunction()>Yes</button
                <div>
                    First Number: <input type="number" id="firstnumber" value=0 disabled><br>
                    Second Number: <input type="number" id="secondnumber" value=0 disabled><br>
                </div>
 </body>

3
  • 1
    onClick should be onclick! Commented May 29, 2017 at 9:44
  • Events in javascript are all lower case there is no camel case for events onclick not onClick Commented May 29, 2017 at 9:46
  • <button onClick="myFunction()">Yes</button> Commented May 29, 2017 at 9:47

2 Answers 2

3

You have written wrong selector here, check updated snippet below:

 function myFunction() {
  document.getElementById("firstnumber").disabled = false;
   document.getElementById("secondnumber").disabled = false;
}
Perform Operation?: <br>
<button onClick=myFunction()>Yes</button
<div>
    First Number: <input type="number" id="firstnumber" value=0 disabled><br>
    Second Number: <input type="number" id="secondnumber" value=0 disabled><br>
</div>

Sign up to request clarification or add additional context in comments.

Comments

1

Your code is ok. Just you are using either wrong id or you have forgot to add the used id to your input. :-)

So either remove extracharges from below code and add firstnumber or secondnumber as per requirement or add input with extracharges as id.

function myFunction() { document.getElementById("extracharges").disabled = false; }

As pointed out in other answers and comments about case sensivity of JavaScript is right, but when you use event handlers as attribute (in html) then most of the browser understands it irrespective of its case.

Check this SO answer for more details!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.