SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: simple question

  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple question

    I have absolutely no knowledge of JS but I just need to use it here if someone can help me with 2 or 3 lines of code.

    I have a selectbox, name=h_location_id.
    values: 1,2,3...10, 'other'

    I have a text box, name=h_location_name , starts off disabled.

    Now when the option OTHER is selected in the selectbox I want to enable the text box.

    Anyone?

    ps just for illustration this is the code i had tried to put together myself which wasnt working at all:

    Code:
    <script type="text/javascript">
    <!--
    window.onload = function start() {
    document.forms[0].h_location_name.disabled = true;
    }
    
    //getSelect(document.forms[0].h_location_id)
    
    function chgtx(a) {
    
    
       if (a == 'other') {
          document.forms[0].h_location_name.disabled = false;
       }
    }
    
    
    // -->
    </script>
    
    
            <select name='h_location_id' onchange='chgtx(javascript:this.value);'>
    
    <option value='1'>1</option>
    <option value='2'>2</option>
    .
    .
    .
    <option value='other'>Other</option>
    
    </select>

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks fine, except the onchange="..." bit.

    Anything in the onchange="" is script anyway, so you don't need the javascript: bit when passing in the function parameter. Just:

    onchange='cgtx(this.value)'

    should work fine.

    NickJ

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great, it's working. cheers!


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
  •