how can I disable and enable input type?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idsanjeev
    New Member
    • Oct 2007
    • 241

    how can I disable and enable input type?

    Hi
    its urgent
    how can enable and desable the input field with condition like
    if rs("field")=1 then
    desable
    elseif re("field")=2 then
    enable
    end if
    and that after chek if the input type is enable then manadatory field can't null
    thanks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    With JavaScript, you'd use the disabled property. However, if you're going to set it whilst the page is loading with ASP, just include it within the tag:
    [code=html]<input type="text" <% if it should be disabled, just print out: disabled="true" %> ...>[/code]

    Re. the validation, please provide more details.

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      Hi..
      u can used directly in page
      like
      [HTML]<input type='control- text/button etc' name='' id='' <%if rs("field")=1 then%>
      disabled=true <%elseif re("field")=2 then%>disabled= false<%end if%>>[/HTML]

      Comment

      • idsanjeev
        New Member
        • Oct 2007
        • 241

        #4
        hi
        I wants to use it in asp with vbscripts
        and my need is to if selected option is floopy and cd then purpose Input filed is enable(show) ohterwiese purpose input field is(hide)
        Thanks

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          hi ...

          i'm not familiar with vb-script but in case you want to set the disabled-attribute dynamically then use something like this (javascript):

          [CODE=javascript]
          var input_node = document.getEle mentById('your_ input_node_id') ;

          // to disable the box
          input_node.setA ttribute('disab led', 'disabled');

          // to make it readonly (text stays selectable)
          input_node.setA ttribute('reado nly', 'readonly');

          // to enable it simply remove the attributes
          input_node.remo veAttribute('di sabled');

          // or
          input_node.remo veAttribute('re adonly');
          [/CODE]
          kind regards

          Comment

          • idsanjeev
            New Member
            • Oct 2007
            • 241

            #6
            hello
            where i have to use it can you sugest any position of code .
            code would write within javascript tag

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              hi ...

              you have to assign an eventhandler to your select-element and call a function:

              [HTML]<select name="my_name" onchange="toggl e_state(this);" >[/HTML]
              now in the head of your page define the script-node:

              [CODE=javascript]<script type="text/javascript">
              function toggle_state(ob j) {
              // here we check the value of your select-box
              var val = obj.value == 'floppy_cd';

              var input_node = document.getEle mentById('your_ input_node_id') ;

              if (val) {
              input_node.setA ttribute('reado nly', 'readonly');
              } else {
              input_node.remo veAttribute('re adonly');
              }
              }
              </script>
              [/CODE]
              kind regards

              Comment

              • idsanjeev
                New Member
                • Oct 2007
                • 241

                #8
                Hello
                My need is if option value is slected cd or floopy then show input filed if option selected is cartidge then hide input filed but when the above code is used no any chnges in forms so please help me in this

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  you have to adapt the val-check to your option values of course.

                  are you sure that there are no changes? :) ... try to input something in case it should have been readonly ...

                  and please now tell clearly: should it be disabled, readonly or hidden?

                  kind regards

                  ps: please post your option html-code

                  Comment

                  • idsanjeev
                    New Member
                    • Oct 2007
                    • 241

                    #10
                    Hi sorry
                    I think i can't give you crrect need or little mistak
                    ok i am trying to decribe in brif
                    i have a form that has option select from table and click on add for requition of material that is in loop
                    my need is if select option is cd or floppy then automatic show input field for input purpose and if option is selected cartidge then hide input field and the requestion is submitted one by one in loop i can't able to do this.there are three field in select option cd,floppy and cartidge
                    code for select option
                    Code:
                         <option Selected Value>Select Item</option>
                    <%
                    Set RSITEM = CON.EXECUTE("SELECT * FROM CONSUM_ITEMS ORDER BY Item_code")
                    %>
                    <%
                    Do While Not RSITEM.EOF
                    %>        <option Value="<%=RSITEM("Item_code")%>"><%=RSITEM("Item_desc")%></option>
                    <%
                    
                    RSITEM.MoveNext
                    Loop
                    thanks

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5390

                      #11
                      then we have to do some adaptions, here are the step-by-step hints:

                      1. give your input node an id and change the function accordingly ... so replace 'your_input_nod e_id' with your id

                      2. add the onchange-attribute the way i showed you

                      3. watch the magic ;)

                      [CODE=javascript]<script type="text/javascript">
                      function toggle_state(ob j) {
                      // here we check the value of your select-box
                      var val = obj.value == 'cartridge';

                      var input_node = document.getEle mentById('your_ input_node_id') ;

                      input_node.styl e.visibility = val ? 'hidden' : 'visible';
                      }
                      </script>
                      [/CODE]
                      kind regards

                      Comment

                      • idsanjeev
                        New Member
                        • Oct 2007
                        • 241

                        #12
                        [CODE=html]
                        <b>Purpose( In case of CD/FLOPPY )</b> &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;
                        <input type="text" name="purpose" id="purpose" style="width:40 0px" maxlength="150" ></td></tr>
                        [/CODE]
                        [CODE=javascript]
                        <script language="javas cript">
                        function toggle_state(ob j) {
                        // here we check the value of your select-box
                        if var val = obj.value == 'cartridge';

                        var input_node = document.getEle mentById('purpo se');

                        input_node.styl e.visibility = val ? 'hidden' : 'visible';
                        }

                        </script>
                        [/CODE]
                        i chnges it like this is the incorrect if not then no magic

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          did you add the onchange:

                          [HTML]<select name="my_name" onchange="toggl e_state(this);" >[/HTML]
                          to your select-box too?

                          kind regards

                          Comment

                          • idsanjeev
                            New Member
                            • Oct 2007
                            • 241

                            #14
                            hi
                            ya use this
                            [HTML]<option Value="<%=RSITE M("Item_code")% >" onchange="toggl e_state(this);" ><%=RSITEM("Ite m_desc")%></option>[/HTML]

                            Comment

                            • gits
                              Recognized Expert Moderator Expert
                              • May 2007
                              • 5390

                              #15
                              hi ...

                              there is an error here, i overlooked it the first time, sorry, your adaption has the following error:

                              [CODE=javascript]if var val = obj.value == 'cartridge';[/CODE]
                              you don't need the if here ;)

                              kind regards

                              Comment

                              Working...