0

I have two fields on my webpage. When one of then is focused I want to disable the other one, but if the user then clicks the disabled field, I want it to disable the first fields and then enable the new focused field. Is this possible in javascript?

so far I've tried:

<script lang="text/javascript">

        function disableSum(){
            document.getElementById('BugID').disabled=false;
            document.getElementById('Summary').disabled=true;
            console.log('Sum Disabled');
        }

        function disableBug(){
            document.getElementById('BugID').disabled=true;
            document.getElementById('Summary').disabled=false;
            console.log('Bug Disabled');
        }

        function checkInput(){

        }

    </script>
Shahab
  • 1,857
  • 6
  • 23
  • 28

2 Answers2

2

The following idea might seem a little bit complicated, but you could play with a pair of visible/hidden fields to get this behavior.

See how it behaves here:

http://jsfiddle.net/TQxSh/

Christophe
  • 25,975
  • 25
  • 91
  • 136
0

From w3schools.com:

The disabled property sets or returns whether an element is disabled, or not.

A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray by default in browsers.

Zack Macomber
  • 6,392
  • 13
  • 55
  • 98
  • is there anything similar to the disabled attribute that will allow me to do what I want? – Shahab Feb 16 '12 at 20:30
  • @ManseUK - wow - there's been some real mess-ups there based on that site. I will say though that I have found w3schools very helpful in the past many a time when needing to look up css and javascript attributes and use them. – Zack Macomber Feb 16 '12 at 20:35
  • @ManseUK - sorry, but some of the things that w3fools.com is purporting are not correct - for instance, they say "Professional web developers do not recommend the use of WYSIWYG editors." There are many web developers that use and highly recommend tools like Dreamweaver for development. I think a lot of opinions are expressed at that site but they aren't necessarily absolutely true. – Zack Macomber Feb 16 '12 at 20:46