www.webdeveloper.com
Results 1 to 8 of 8

Thread: Disable Form Field with Javascript

  1. #1
    Join Date
    Feb 2011
    Posts
    4

    Question Disable Form Field with Javascript

    Hi,
    I'm trying to to enable a text field with javascript (it is disabled originally). The name of the text field is duo[x]. (I need to keep the brackets so php will reconize it as an array.)
    In javascript, I was trying to use to use: document.form.duo[x].disabled = false; (but that didn't work).

    Here is what I have right now:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function change(code) {
    
    var a = "Duo[" + code + "]"; document.form.a.disabled = false;
    } </script> </head> <body> <form name="form"> <select name="select" onchange="return change(x)"> <option>Opt 1</option> <option>Opt 2</option> </select> <input type="text" name="duo[x]" disabled></input> </form> </html>
    Thanks,

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    You have only 1 input so why do you have to send it as an array? and where is x defined in
    Code:
    onchange="return change(x)"

  3. #3
    Join Date
    Feb 2011
    Posts
    4
    I will have many more elements...I wanted to give you an example of what 1 element would look like and how I was trying to do it.

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    Quote Originally Posted by bostonfdt View Post
    I will have many more elements...I wanted to give you an example of what 1 element would look like and how I was trying to do it.
    ok, then what is the x referring to in
    Code:
    onchange="return change(x)"

  5. #5
    Join Date
    Mar 2010
    Posts
    2,803
    and in your 1st post you said

    I'm trying to to enable a text field with javascript (it is disabled originally).
    So which of those many elements do you want to enable?

    Also with your current code, no matter which option you select from the select list, the input element will be enabled. Is that what you really need?

  6. #6
    Join Date
    Feb 2011
    Posts
    4
    x in
    Code:
    return change(x)
    will be the same number in
    Code:
    <input type="text" name="x" disabled>
    Another text box and drop down menu on the page would have
    Code:
    return change(y)
    and
    Code:
    <input type="text" name="y" disabled>
    That way I could use the same JavaScript function

  7. #7
    Join Date
    Mar 2010
    Posts
    2,803
    But you originally named the input name="duo[x]" and now you're saying the name is just "x" or "y" and so on for each input. You can't have it both ways.

    You need to decide on how the inputs will be named or describe better what actual functionality you want and we can name the elements appropriately for you.

  8. #8
    Join Date
    Feb 2011
    Posts
    4
    I just figured it out (I used a different method)...
    Thanks for your help!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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