2014-02-25 50 views
-3

我只知道一點Java和PHP。我想知道,是否有可能,例如,「IF radiobutton1 AND Radiobutton2 AND radiobutton3 AND radiobutton4 is click」,然後textbox1的值爲10. else IF radiobutton1 AND Radiobutton2 AND radiobutton5 AND radiobutton6 is click then textbox2的值是20" ?我想要做這樣的事情。if else。 JavaScript的。在文本框中顯示結果

我的代碼是在這裏和輸出:

<html> 
<head> 
<title>Belle</title> 
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 
</head> 

<body style="margin: 0; border: 0;"> 

<table border=0 align="center"> 
    <th colspan="3"><h2><font color="black" 



<th> 


</font></h2></th> 


    <tr><td> 
    <table border="0" bordercolorlight="#FFFF99"> 

     <th align="center" colspan="3" bgcolor="black"><font color="white">FIRST</font></th> 
      <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> 
       <tr> 
       <td><input type="radio" name="flight" value="tnternational">International</td > 
       <td><input type="radio" name="flight" value="Domestic">Domestic</td > 
       </tr> 
      <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> 

     <th align="center" colspan="3" bgcolor="black"><font color="white">SECOND</font></th> 
     <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> 
     <tr> 
      <td>Type:</td> 
      <form action="javascript:return true;" name="form1"> 
      <td><input type="radio" name="group1" value="opt1" id="opt1" onclick="show()"><label for="opt1">One Way</label></td>    
      <td><input type="radio" name="group1" value="opt2" id="opt2" onclick="show()"><label for="opt2">Round Trip</label></td> 
     </tr>  
     <tr> 
      <td>Insurance:</td> 
      <td><input type="radio" id="m1" name="insurance" value='250'/>Yes</td> 
      <td><input type="radio" id="m2" name="insurance" value='0'/>No</td> 
     </tr> 
     <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> 

     <th align="center" colspan="3" bgcolor="black"><font color="white">THIRD</font></th> 
     <tr><td>&nbsp;<td>&nbsp;</td><td>&nbsp;</td></td><td > 
     <tr> 
      <td>&nbsp;</td> 
      <td><center>One</center></td> 
      <td><center>Two</center></td> 
     </tr> 
     <tr> 
      <td> 
      B:</br></br></br></br></br></br> 
      S1: </br></br></br></br> 
      S2:</br></br> 
      H: </br></br> 
      I:</br></br> 
      </td> 
      <td> 
      <input type="radio" value="0" name="bgto">None<br/> 
      <input type="radio" value="201.60" name="bgto">10kg<br/> 
      <input type="radio" value="201.60" name="bgto">15kg<br/> 
      <input type="radio" value="336.00" name="bgto">20kg<br/> 
      <input type="radio" value="672.00" name="bgto">30kg<br/> 
      <input type="radio" value="1232.00" name="bgto">45kg<br/> 
      <input type="radio" value="0" name="ssto">None<br/> 
      <input type="radio" value="257.60" name="ssto">Premium<br/> 
      <input type="radio" value="145.60" name="ssto">Standard<br/> 
      <input type="radio" value="1120.00" name="seto">Yes<br/> 
      <input type="radio" value="0" name="seto">No<br/> 
      <input type="radio" value="50" name="hmto">Yes<br/> 
      <input type="radio" value="50" name="hmto">No<br/> 
      <input type="radio" value="336" name="infto">Yes<br/> 
      <input type="radio" value="0" name="infto">No<br/> 
      </td> 


      <td><div id="from"> 
      <input type="radio" value="opt2" name="bgfrom">None<br/> 
      <input type="radio" value="opt2" name="bgfrom">10kg<br/> 
      <input type="radio" value="opt2" name="bgfrom">15kg<br/> 
      <input type="radio" value="opt2" name="bgfrom">20kg<br/> 
      <input type="radio" value="opt2" name="bgfrom">30kg<br/> 
      <input type="radio" value="opt2" name="bgfrom">45kg<br/> 
      <input type="radio" value="opt2" name="ssfrom">None<br/> 
      <input type="radio" value="opt2" name="ssfrom">Premium<br/> 
      <input type="radio" value="opt2" name="ssfrom">Standard<br/> 
      <input type="radio" value="opt2" name="ssfrom">Stan-Plus<br/> 
      <input type="radio" value="opt2" name="sefrom">Yes<br/> 
      <input type="radio" value="opt2" name="sefrom">No<br/> 
      <input type="radio" value="opt2" name="hmfrom">Yes<br/> 
      <input type="radio" value="opt2" name="hmfrom">No<br/> 
      <input type="radio" value="opt2" name="inffrom">Yes<br/> 
      <input type="radio" value="opt2" name="inffrom">No<br/> 
      </div></td> 
     </tr> 
     </td></form> 
    </table> 
    <br/> 

    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
    <td> 
    <table border="0" bordercolorlight="BLACK"> 
    <th align="center" colspan="2" bgcolor="bLACK"><font color="white">CALCULATE</font></th> 

    <tr><td>&nbsp;</td><td>&nbsp;</td></tr> 
    <form name="frmMain"> 
    <tr><td>F: </td><td><input type="text" name="txtNumberA" value="0"> </td></tr> 
    <tr><td>I: </td><td><input type="text" id="txtNumberB" name="txtNumberB" value=""> </td></tr> 
    <tr><td>B: </td><td><input type="text" id="txtNumberD" name="txtNumberD" value=""> </td></tr> 
    <tr><td>S1: </td><td><input type="text" id="txtNumberE" name="txtNumberE" value=""> </td></tr> 
    <tr><td>S2: </td><td><input type="text" id="txtNumberF" name="txtNumberF" value=""> </td></tr> 
    <tr><td>H: </td><td><input type="text" id="txtNumberG" name="txtNumberG" value=""> </td></tr> 
    <tr><td>I: </td><td><input type="text" id="txtNumberH" name="txtNumberH" value=""> </td></tr> 
    <tr><td>TOTAL:</td><td><input type="text" name="txtNumberC" value=""> </td></tr> 
    <tr> 
    <td><input type="button" name="btnSum" value="TOTAL" OnClick="fncSum();"></td> 
    <td align="center">&nbsp;</td> 
    </form> 
    </tr> 
    <tr><td>&nbsp;</td><td>&nbsp;</td></tr> 
      <script type="text/javascript"> 
      (function($) 
      { 
       $(function() 
       { 
        $('input[type="radio"]').click(function(e) 
        { 
         value = $("input[name=insurance]:checked").val(); 
         $('#txtNumberB').val(value); 
        }); 
       }); 
      })(jQuery); 
      </script> 
      <script type="text/javascript"> 
      (function($) 
      { 
       $(function() 
       { 
        $('input[type="radio"]').click(function(e) 
        { 
         value = $("input[name=bgto]:checked").val(); 
         $('#txtNumberD').val(value); 
        }); 
       }); 
      })(jQuery); 
      </script> 

      <script type="text/javascript"> 
      (function($) 
      { 
       $(function() 
       { 
        $('input[type="radio"]').click(function(e) 
        { 
         value = $("input[name=ssto]:checked").val(); 
         $('#txtNumberE').val(value); 
        }); 
       }); 
      })(jQuery); 
      </script> 

      <script type="text/javascript"> 
      (function($) 
      { 
       $(function() 
       { 
        $('input[type="radio"]').click(function(e) 
        { 
         value = $("input[name=seto]:checked").val(); 
         $('#txtNumberF').val(value); 
        }); 
       }); 
      })(jQuery); 
      </script> 

      <script type="text/javascript"> 
      (function($) 
      { 
       $(function() 
       { 
        $('input[type="radio"]').click(function(e) 
        { 
         value = $("input[name=hmto]:checked").val(); 
         $('#txtNumberG').val(value); 
        }); 
       }); 
      })(jQuery); 
      </script> 

      <script type="text/javascript"> 
      (function($) 
      { 
       $(function() 
       { 
        $('input[type="radio"]').click(function(e) 
        { 
         value = $("input[name=infto]:checked").val(); 
         $('#txtNumberH').val(value); 
        }); 
       }); 
      })(jQuery); 
      </script>  
    <script> 
     var dl = document.getElementById('from'); 
     dl.style.visibility = 'hidden'; 
     function show() 
     { 
      for (var i=0; i < document.form1.group1.length; i++) 
       { 
       if (document.form1.group1[i].checked) 
        { 
        var radio = document.form1.group1[i].value; 
        } 
       } 
       if (radio == 'opt2') 
        { 
         dl.style.visibility = 'visible'; 
        } 
       else 
        { 
         dl.style.visibility = 'hidden'; 
        } 
     } 
    </script> 


    <script> 
     function calculate_total(className, total_text) 
     { 
      var elements = document.getElementsByTagName("input"); 
      var total = 0; 
      for(var i = 0; i < elements.length; ++i) 
      { 
       if(elements[i].className == className) 
       { 
        total += parseInt(elements[i].value); 
       } 
      } 
      document.getElementById(total_text).innerHTML = "Total: " + total; 
     } 
    </script> 

     <script> 
     function fncSum() 
     { 
      if(isNaN(document.frmMain.txtNumberA.value) || document.frmMain.txtNumberA.value == "") 
      { 
      alert('(Number A)Please input Number only.'); 
      document.frmMain.txtNumberA.focus(); 
      return; 
      } 

      if(isNaN(document.frmMain.txtNumberB.value) || document.frmMain.txtNumberB.value == "") 
      { 
      alert('(Number B)Please input Number only.'); 
      document.frmMain.txtNumberB.focus(); 
      return; 
      } 
      if(isNaN(document.frmMain.txtNumberD.value) || document.frmMain.txtNumberD.value == "") 
      { 
      alert('(Number D)Please input Number only.'); 
      document.frmMain.txtNumberD.focus(); 
      return; 
      } 
      if(isNaN(document.frmMain.txtNumberE.value) || document.frmMain.txtNumberE.value == "") 
      { 
      alert('(Number E)Please input Number only.'); 
      document.frmMain.txtNumberE.focus(); 
      return; 
      } 
      if(isNaN(document.frmMain.txtNumberF.value) || document.frmMain.txtNumberF.value == "") 
      { 
      alert('(Number F)Please input Number only.'); 
      document.frmMain.txtNumberF.focus(); 
      return; 
      } 
      if(isNaN(document.frmMain.txtNumberG.value) || document.frmMain.txtNumberG.value == "") 
      { 
      alert('(Number G)Please input Number only.'); 
      document.frmMain.txtNumberG.focus(); 
      return; 
      } 
      if(isNaN(document.frmMain.txtNumberH.value) || document.frmMain.txtNumberH.value == "") 
      { 
      alert('(Number H)Please input Number only.'); 
      document.frmMain.txtNumberH.focus(); 
      return; 
      } 

      document.frmMain.txtNumberC.value = parseFloat(document.frmMain.txtNumberA.value) + 
               parseFloat(document.frmMain.txtNumberB.value) + 
               parseFloat(document.frmMain.txtNumberD.value) + 
               parseFloat(document.frmMain.txtNumberE.value) + 
               parseFloat(document.frmMain.txtNumberF.value) + 
               parseFloat(document.frmMain.txtNumberG.value) + 
               parseFloat(document.frmMain.txtNumberH.value); 
     } 
     </script> 
    </body> 
</html> 
+0

對我來說最好的方法是:第一。閱讀文檔;第2位。嘗試一些代碼;沒有這些任何答案將是一個廢話... – i100

回答

0

通過jQuery

$('button').bind('click',function(){ 
    if($('#a').is(':checked')&& $('#c').is(':checked')){ 
     $('input').val('Sometext'); 
    } 
}); 

這裏是小提琴http://jsfiddle.net/Goodluck/eay96/ 我不知道你的情況是什麼,但你可以把它換成w ELL:

$('.cb').change(function(){ 
    if($('#a').is(':checked')&& $('#c').is(':checked')){ 
     $('input').val('Sometext'); 
    } 
}); 

和提琴http://jsfiddle.net/Goodluck/eay96/1/

+0

謝謝。仍在努力。我想自動顯示它。但生病嘗試你的,(用一個按鈕):) - 對不起,我沒有關於JavaScript或jquery的背景:( – bellebelurbano

+0

謝謝youuu :)我明白了:) – bellebelurbano

1

這個JavaScript樣本可能是一個良好的開端:

if (document.forms['myForm'].elements["radio1"].checked && 
    document.forms['myForm'].elements["radio2"].checked && 
    document.forms['myForm'].elements["radio5"].checked 
    ) 
{ 
    document.forms['myForm'].elements["textbox2"].value = 10; 

} else if (document.forms['myForm'].elements["radio3"].checked && 
    document.forms['myForm'].elements["radio4"].checked && 
    document.forms['myForm'].elements["radio7"].checked 
    ) 
{ 
    document.forms['myForm'].elements["textbox2"].value = 20; 
} 
+0

謝謝。仍然在工作:)對不起,我沒有關於JavaScript的背景:( – bellebelurbano

+0

它幾乎就像java,你知道一點關於這個網站有一些基礎知識,這將有助於你開始學習,然後我的樣品肯定會有道理: http://www.w3schools.com/js/ – LGSon

+0

謝謝youuu :)我明白了:) – bellebelurbano

0
<html> 
<head> 
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
</head> 
<body> 
<table border="0" bordercolorlight="#FFFF99"> 
<form name="frmMain"> 
    <th align="center" colspan="3" bgcolor="black"><font color="white">FIRST</font></th> 
    <tr><td colspan="3"><center><input type="radio" name="flight" value="International" class="flight" id="intl">International</td ></tr> 

    <th align="center" colspan="3" bgcolor="black"><font color="white">SECOND</font></th> 
    <tr><td>Type:</td> 
     <td colspan="2"><center><input type="radio" name="group1" value="opt1" id="opt1" onclick="show()" class="flight"><label for="opt1">One Way</label></td>    
    </tr>  
    <tr><td>I:</td> 
     <td colspan="2"><center><input type="radio" id="m1" name="insurance" value='0' class="flight"/>Yes 
     <input type="radio" id="m2" name="insurance" value='0' class="flight"/>No</td> 
    </tr> 
    <tr><td>I:</td><td><input type="text" id="txtNumberB" name="txtNumberB" value="0" class="flight"> </td></tr> 

<script> 
$('.flight').change(function(){ 
    if($('#intl').is(':checked')&& $('#opt1').is(':checked')&& $('#m1').is(':checked')) 
     { 
      document.frmMain.txtNumberB.value = 250.00; 
     } 
    if($('#intl').is(':checked')&& $('#opt1').is(':checked')&& $('#m2').is(':checked')) 
     { 
      document.frmMain.txtNumberB.value = 0.00; 
     } 
     }); 
</script> 
</html> 

這樣:) :)謝謝youu。