SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Deactivate form fields.

    Hi

    I have a a list of text fields for a person's name. Then for each textfield there are 5 other input fields to describe the person.

    What I want to do is that when no name for the person is enetered, the fields describing that person will be deactivated.

    For exaple I got "Player 1 - Blue, Tall, France"

    I got 10 of those but when I just put in names for 4 people, the descriptions for the other 6 still appear.

    So, is there a way to deactivate the other form fields if one is left at value=0 ?

  2. #2
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <input type="text" name="nameField1" onchange="if (this.value=='') descField1.disabled=true;">
    (untested)

    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    To further improve on M@rco's example:

    Code:
    <script language="javascript" type="text/javascript">
     function disableBox(theBox){
      if(theBox.value==''){
      theBox.disabled=true;
      }else{
      theBox.disabled=false;
      }
     }
    </script>
    ...
    <input type="text" name="FieldOne" onChange="disableBox(this);" />
    You can also use that code for the onBlur event (when a user moves focus away from the textbox).

    --Vinnie

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or simply:
    Code:
    <input type="text" name="nameField1" onchange="descField1.disabled = (this.value == '') ? true : false;">
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

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