SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    bahrain
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up disabling a textfield

    hi
    i want to disable a textfield when a user selects a perticular value form select filed.
    e.g i m having occupations in select field and when user selects 'others' the textfield should not be disable and disable for all other values.
    its urgent plzzz.....
    regards
    phphelp

  2. #2
    SitePoint Enthusiast Bobbi's Avatar
    Join Date
    Mar 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a javascript issue (if you don't want to reload the whole page with PHP - then you can use the "READONLY" tag inside the <input> field) ... if my memory about javascript doesn't serve me wrong, you can do that with something like
    Code:
    onclick="document.form.textbox.disabled=true"
    in the <option> tags.

  3. #3
    SitePoint Addict battra's Avatar
    Join Date
    Oct 2004
    Location
    Asylum
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <form>
    <select name="occupation" onChange="toggleInput(this.options[this.selectedIndex].value, this.form.other_occupation)">
    <option value="something">Something</option>
    <option value="other">Other</option>
    </select>
    Please specify: <input type="text" name="other_occupation">
    </form>
    
    <script language="JavaScript">
    function toggleInput(selected_value, input_box)
    {
        input_box.disabled = (selected_value != 'other');
        input_box.readonly = (selected_value != 'other');
    }
    </script>


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
  •