Disable field input type in the form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    Disable field input type in the form

    Hi there.

    I have this form with three fields:

    Code:
    <HTML>
    <HEAD>
      
    <script language="javascript">
    <!--
     
     
     function ApriPopup(larg,alte,url) 
    
    { 
    var w = screen.width; 
    var h = screen.height;
     
    var x = Math.round(w / 2) - Math.round(larg / 2); 
    var y = Math.round(h / 2) - Math.round(alte / 2); 
    
    window.open(url,'','width='+larg+',height='+alte+',top='+y+',left='+x+''); 
    } 
    
     
    //-->
    </script>
     
    </HEAD>
     
    <BODY> 
     
    <form method="POST" action="test.asp">
     
      <select size="1" name="Stato">
      <option>Seleziona</option>
      <option value="Assente">Assente</option>
      <option value="Presente">Presente</option>
      </select>
     
      <select size="1" name="Stato_g">
      <option>Seleziona</option>
      <option value="Ferie">Ferie</option>
      <option value="Malattia">Malattia</option>
      <option value="In sede">In sede</option>
      <option value="Fuori sede">Fuori sede</option>
      </select>  
     
    <input type="text" name="ore" size="20">
    <a href="javascript:ApriPoup(500,500,'popup.asp');">
    	<img border="0" src="apripopup.gif" width="12" height="12"></a>
     
    </form>
     
    </BODY>
    </HTML>
    I have to disable the field input type="text" name="ore" AND the link <a href="javascrip t:ApriPoup(500, 500,'popup.asp' );"> when the select "Stato" value "Assente".

    Help please, thanks regards
    Viki1967
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Add a function onchange of Stato. In that function, if value of Stato is Assente, disable all the thing you require to disable, and if value is not Assente, enable them back.

    You may not disable the link, so set its href to "#" or "javascript:void (0)" instead.

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      Thanks, but one example ?

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        [code=javascript]function disOrEnb(sel) {
        document.forms[0].ore.disabled = sel.value == 'Assente' ? true : false;
        document.getEle mentById('link' ).href = sel.value == 'Assente' ? 'javascript:voi d(0)' : 'javascript:Apr iPoup(500,500,\ 'popup.asp\')';
        }[/code]

        Add onchange="disOr Enb(this)" to the select tag.

        Comment

        • viki1967
          Contributor
          • Oct 2007
          • 263

          #5
          Thanks, but sorry not working:



          Code:
          <HTML>
          <HEAD>
            
          <script language="javascript">
          <!--
           
           
           function ApriPopup(larg,alte,url) 
          
          { 
          var w = screen.width; 
          var h = screen.height;
           
          var x = Math.round(w / 2) - Math.round(larg / 2); 
          var y = Math.round(h / 2) - Math.round(alte / 2); 
          
          window.open(url,'','width='+larg+',height='+alte+',top='+y+',left='+x+''); 
          } 
          
          
          function disOrEnb(sel) {
              document.forms[0].ore.disabled = sel.value == 'Assente' ? true : false;
              document.getElementById('link').href = sel.value == 'Assente' ? 'javascript:void(0)' : 'javascript:ApriPoup(500,500,\'popup.asp\')';
          }
          
           
          //-->
          </script>
           
          </HEAD>
           
          <BODY> 
           
          <form method="POST" action="test.asp">
           
            <select size="1" name="Stato" onchange="disOrEnb(this)">
            <option>Seleziona</option>
            <option value="Assente">Assente</option>
            <option value="Presente">Presente</option>
            </select>
           
            <select size="1" name="Stato_g">
            <option>Seleziona</option>
            <option value="Ferie">Ferie</option>
            <option value="Malattia">Malattia</option>
            <option value="In sede">In sede</option>
            <option value="Fuori sede">Fuori sede</option>
            </select>  
           
          <input type="text" name="ore" size="20">
          <a href="javascript:ApriPoup(500,500,'popup.asp');">
          	<img border="0" src="php/modifica.gif" width="12" height="12"></a>
           
          </form>
           
          </BODY>
          </HTML>

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Make this change...

            <a id="link" href="javascrip t:ApriPoup(500, 500,'popup.asp' );">

            Comment

            • viki1967
              Contributor
              • Oct 2007
              • 263

              #7
              Thanks.

              When "Stato" is "Presente" not working:

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by viki1967
                Thanks.

                When "Stato" is "Presente" not working:

                http://www12.asphost4free.com/viki1967/form.htm
                In this link I can see it is working!!

                Which browser are you using?

                Comment

                • viki1967
                  Contributor
                  • Oct 2007
                  • 263

                  #9
                  I use Internet Explorer, this is error:

                  Stato = Presente
                  Stato_g = Ferie

                  If you click on image modifica.gif:

                  Comment

                  • viki1967
                    Contributor
                    • Oct 2007
                    • 263

                    #10
                    Yes !!!

                    Code:
                    'javascript:ApriPoup(500,500,\'popup.asp\')';
                    Code:
                    'javascript:ApriPopup(500,500,\'popup.asp\')';

                    Not ApriPoup but ApriPopup

                    THANKS !!!!!!
                    Bye

                    Comment

                    • viki1967
                      Contributor
                      • Oct 2007
                      • 263

                      #11
                      Sorry, it's possible change image src="php/modifica.gif" with src="php/NoModifica.gif" when stato = Assente ?

                      Comment

                      • hsriat
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1653

                        #12
                        Originally posted by viki1967
                        Sorry, it's possible change image src="php/modifica.gif" with src="php/NoModifica.gif" when stato = Assente ?
                        yeah, add this similarly to the existing function.

                        Comment

                        • viki1967
                          Contributor
                          • Oct 2007
                          • 263

                          #13
                          Sorry, I dont know... :(

                          Comment

                          • hsriat
                            Recognized Expert Top Contributor
                            • Jan 2008
                            • 1653

                            #14
                            Originally posted by viki1967
                            Sorry, I dont know... :(
                            Here is an example which can help you.

                            Comment

                            • viki1967
                              Contributor
                              • Oct 2007
                              • 263

                              #15
                              Thanks, but as edit function disOrEnb ?

                              Comment

                              Working...