Sami Al-Subhi
Sami Al-Subhi

Reputation: 4662

Can't execute a JavaScript event using 'onclick' button

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()">

Upvotes: 2

Views: 439

Answers (2)

gprathour
gprathour

Reputation: 15333

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

Upvotes: -1

zequinha-bsb
zequinha-bsb

Reputation: 719

<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).

Upvotes: 2

Related Questions