dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Textbox and Selectbox

  1. #1
    Join Date
    May 2006
    Posts
    4

    Textbox and Selectbox

    Hello good people. I need some help here. I dont know if it's possible, but i got 1 textbox and 1 selectbox.

    What i want is:

    If the textbox is not empty, gray out/disable the selectbox, and if something in the selectbox is selected, gray out the textbox.

    is this possible, and if so, how do i do it?

    Many thanx

    -OmiCron-

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    Perhaps something like this:
    HTML Code:
    <form action="" onsubmit="return false;">
      <p>Choice:
      <select size="1" name="choice"
       onchange="return checkControls(this, other)">
        <option>[select one]</option>
        <option>apples</option>
        <option>bananas</option>
        <option>cantaloupe</option>
      </select><br>
      Other:
      <input type="text" name="other" size="20"
       onchange="return checkControls(choice, this)"></p>
    </form>
    
    <script type="text/javascript">
    <!--//
    function checkControls(sel, txt) {
      if(sel.selectedIndex < 1) {
        txt.disabled = false;
        if(/^\s*$/.test(txt.value)) {
          sel.disabled = false;
        } else {
          sel.selectedIndex = 0;
          sel.disabled = true;
        }
      } else {
        txt.value = "";
        txt.disabled = true;
      }
      return true;
    }
    //-->
    </script>

  3. #3
    Join Date
    May 2006
    Posts
    4
    Hey phpnovice, thanks for taking a look at my problem, this was EXACTLY what i needed!

    This will be used alot :P

    Cheers

    -OmiCron-

  4. #4
    Join Date
    Dec 2004
    Posts
    8,637
    You're welcome.

    Cheers.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles