2

I'm trying to execute 'select' function via onclick but it doesn't work.

<script type="text/javascript">
  function select() {
      document.getElementById('select').disabled = true;        
  }
</script>

<input type="button" id="select" value="OK" onclick="select()">
1
  • Does your page have any other JavaScript errors? Have you tried using a different id? Commented Nov 20, 2011 at 4:46

2 Answers 2

2
<script type="text/javascript">
    function mySelect() {
        document.getElementById('myselect').setAttribute('disabled');        
    }
</script>

<input type="button" id="myselect" value="OK" onclick="mySelect()">

Two things:

a) avoid using internal names for functions or variables. select is an html reserved word; and

b) the right way to set is using the setAttribute.

Done! (and tested).

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

Comments

-1

Try changing the name of the Function from select to something else. select is html reserved word so doesn't work.

2 Comments

to check working if the function is working or not, put alert() in your method.
-1 "select" is not a javascript keyword. If I could, I'd -2 for your advocating the use of alert() in your subsequent comment. Always test using console.log (ff/chrome/IE9+ support this method).

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.