Sending disabled form elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • truptivk
    New Member
    • Sep 2009
    • 14

    Sending disabled form elements

    Hello all,

    I am stuck with my problem, and being a JS novice, I need your help. I'd appreciate it if anyone could.

    I have a page, in which depending on value selected from dropdown-1 (for example), I need to disable or enable few other elements in the page.

    I then need to send all these values via form submit to another page. Problem is, I discovered that disabled elements cannot be sent via form submits.

    My solution is that I use the readOnly property, instead of disabled. But the following code:

    Code:
    if (value == "Ordered" || value == "Planned")
    {
        	 document.myForm.myElement.readOnly = false;
    }
    else if (value != "Disposed")
    {
        	 document.equipment.myElement.readOnly = true;
    }
    The field myElement in my case is a drop down.

    Thanks for the help.

    Regards,
    Trupti
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Is the form name myForm or equipment?

    Comment

    • truptivk
      New Member
      • Sep 2009
      • 14

      #3
      Originally posted by acoder
      Is the form name myForm or equipment?
      Hello,

      I'm sorry; its actually 'equipment', but because I didn't want to confuse anyone, I decided to substitute it with 'myForm'. Evidently, I skipped it in one place.

      Let us take the name to be 'myForm'. I'm re-writing my above code snippet here:

      Code:
      if (value == "Ordered" || value == "Planned")
      {
               document.myForm.myElement.readOnly = false;
      }
      else if (value != "Disposed")
      {
               document.myForm.myElement.readOnly = true;
      }
      Thanks,
      Trupti

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can't set a select element to read-only. Was that what you wanted to do?

        Comment

        • truptivk
          New Member
          • Sep 2009
          • 14

          #5
          Originally posted by acoder
          You can't set a select element to read-only. Was that what you wanted to do?
          Yes, instead of disabling based on value in "value", which would not send the myElement on form submit, I thought I could make it readOnly.

          Since according to you I cannot set it to readOnly like that, what I tried was to set it to disabled, but again enable it just before form submit. This ensured that the value of myElement was submitted. Not an optimum solution, but it works.

          Do you have any other ideas?

          Thanks,
          Trupti

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Another way would be to hide the element and show it when required.

            Comment

            • truptivk
              New Member
              • Sep 2009
              • 14

              #7
              Originally posted by acoder
              Another way would be to hide the element and show it when required.
              Yes, which is what I'm doing effectively. Thank you very much for taking time out to reply to my query.

              Trupti

              Comment

              Working...