Niedawno zaczałęm się uczyć JS, natknąłem się na pewien problem.

Chciałbym, żeby input radio o nazwie act i wartości 2 robił się disabled i checked przechodziło automatycznie na act o wartości 1, gdy w polu select wybrana zostanie opcja a

Kawałek mam napisane:

  1. <form name="f">
  2. <SELECT NAME="select" onBlur="check()">
  3. <OPTION SELECTED>
  4. <OPTION value="a">a
  5. <OPTION value="b">b
  6. <br>
  7. <input type="radio" name="act" value="1">active
  8. <br>
  9. <input type="radio" name="act" value="2">active/notactive
  10. </form>
  11.  
  12. <script language="JavaScript">
  13. <!--
  14. function check(){
  15.        if(document.f.select.options[document.f.select.selectedIndex].value == "a"){
  16.            // co tu napisać?
  17.        }
  18. }
  19.  
  20. //-->


ale nie wiem co wstawić w ramiona warunku. Podglądywałem inne skrypty, ale dla mnie nie jest to zrozumiałe i nie umiem sobie z tym poradzić sad.gif

proszę o pomoc.

P.S. Jak robię tak:

  1. <form name="f">
  2. <SELECT NAME="select" onBlur="check()">
  3. <OPTION SELECTED>
  4. <OPTION value="a">a
  5. <OPTION value="b">b
  6. <br>
  7. <input type="checkbox" name="act2" value="1">
  8. </form>
  9.  
  10. <script language="JavaScript">
  11. <!--
  12. function check(){
  13.        if(document.f.select.options[document.f.select.selectedIndex].value == "a"){
  14.            // co tu napisać?
  15.                  document.f.act2.disabled = true;
  16.        }
  17.            else{
  18.                  document.f.act2.disabled = false;
  19.            }
  20. }
  21.  
  22. //-->


to wszystko działa... ale mam problem z polami input o typie radio.

edit://

Już mam kod... temat nieaktualny. Faxe masta mi napisał (thx):

  1.  
  2.      <title> Hihi </title>
  3.      <script type="text/javascript">
  4.            function zdisableduj()
  5.            {
  6.                  var wy;
  7.                  
  8.                  try
  9.                  {
  10.                        document.forms[0].foo[2].disabled = true;
  11.                  }
  12.                  catch( e )
  13.                  {
  14.                        wy = '';
  15.                        
  16.                        for( el in e )
  17.                              wy += el +': '+ e[el] +'\n';
  18.                        
  19.                        alert( wy );
  20.                  }
  21.            }
  22.      </script>
  23. </head>
  24.  
  25.  
  26. <form action="http://www.wp.pl/" method="get">
  27.  
  28.      <label>
  29.            <input type="radio" name="foo" value="bar" />
  30.            bar
  31.      </label>
  32.      
  33.      <label>
  34.            <input type="radio" name="foo" value="baz" />
  35.            baz
  36.      </label>
  37.      
  38.      <label>
  39.            <input type="radio" name="foo" value="spam" />
  40.            spam
  41.      </label>
  42.      
  43.      <label>
  44.            <input type="radio" name="foo" value="eggs" />
  45.            eggs
  46.      </label>
  47.      
  48. </form>
  49.  
  50. <div style="border: 1px dashed red; cursor: pointer;" onclick="zdisableduj();">
  51.      Kliku-klik! (zdisableduje &quot;spam&quot;)
  52. </div>
  53.  
  54. </body>
  55. </html>