2016年6月2日 星期四

亂數不可重複 (以3個亂數為例)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
 <Script type ="text/javascript">
var rx1=0,rx2=0,rx3=0,maxNum=0,minNum=0;
maxNum=9;
mixNum=0;

rx1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
rx2=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
rx3=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;

while(rx1==rx2)
{
 rx1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;

}
while(rx2==rx3 || rx3==rx1 )
{
 rx3=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;

}

document.write("亂數"+rx1,rx2,rx3);

 </Script>
</body>
</html>

亂數可重複 (3個亂數為例)

<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
 <Script type ="text/javascript">
var rx1=0,rx2=0,rx3=0,maxNum=0,minNum=0;
maxNum=9;
mixNum=0;

rx1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
rx2=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
rx3=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;

document.write("亂數"+rx1,rx2,rx3);

 </Script>
</body>
</html>

2016年5月20日 星期五

產生隨機亂數化成圓餅圖

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

    <script type="text/javascript">


      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
 
      var a,b,c;
      a=0;
      b=0;
      c=0;
var n1=n2=n3=n4=0;
   function Random() {

var maxNum = 4;
var minNum = 0;

    n1 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
    n2 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
    n3 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
    n4 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;  
   
  drawChart();

 
}

      function add() {
     
 var radio1 = document.getElementsByName("v1");
 var radio2 = document.getElementsByName("v2");
 var radio3 = document.getElementsByName("v3");

   for(var i=0;i<radio1.length;i++)
   {
     if(radio1.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


     
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;
break;
     }
   }
for(var i=0;i<radio2.length;i++)
   {
     if(radio2.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


     
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;
break;
     }
   }
for(var i=0;i<radio3.length;i++)
   {
     if(radio3.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


     
     document.getElementById('c1').value=a;
     document.getElementById('c2').value=b;
     document.getElementById('c3').value=c;
break;
     }
   }







      }

      function drawChart() {
     
       var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['1',     n1],
          ['2',     n2],
          ['3',     n3],
          ['4',     n4]  
        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>

<h1>你選了什麼?</h1>
<input name="v1" type="radio" value="300年">300年        
<input name="v1" type="radio" value="400年">400年            
<input name="v1" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="300年">300年        
<input name="v2" type="radio" value="400年">400年            
<input name="v2" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="300年">300年        
<input name="v3" type="radio" value="400年">400年            
<input name="v3" type="radio" value="1000年">1000年
<br>


c1:
 <input type="text" name="FirstName" id="c1" <br><br/>

 c2:
 <input type="text" name="address" id="c2" <br></br>

 c3:
 <input type="text" name="address" id="c3" <br></br>


 <input type="button" value="Random" onclick="Random()"/>
<input type="button" value="submit" onclick="add()"/>
  <div id="piechart" style="width: 900px; height: 500px;"></div>

  </body>
</html>

2016年5月13日 星期五

網頁選項,以圓餅圖統計結果

<!DOCTYPE html ><html >
<head>
    <title>
    Form
    </title>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
var a;
var b;
var c;
var total;
function check1() {
a=0;
b=0;
c=0;
total=0;
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");
var radio4=document.getElementsByName("v4");
var radio5=document.getElementsByName("v5");
var radio6=document.getElementsByName("v6");
var radio7=document.getElementsByName("v7");
var radio8=document.getElementsByName("v8");
var radio9=document.getElementsByName("v9");
var radio10=document.getElementsByName("v10");
var flag=new Array();
   for(var i=0;i<radio1.length;i++){
     if(radio1.item(i).checked==true)        {
       flag[1]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio2.length;i++){
     if(radio2.item(i).checked==true)        {
       flag[2]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio3.length;i++){
     if(radio3.item(i).checked==true)        {
       flag[3]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio4.length;i++){
     if(radio4.item(i).checked==true)        {
       flag[4]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio9.length;i++){
     if(radio9.item(i).checked==true)        {
       flag[9]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio5.length;i++){
     if(radio5.item(i).checked==true)        {
       flag[5]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio10.length;i++){
     if(radio10.item(i).checked==true)        {
       flag[10]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio6.length;i++){
     if(radio6.item(i).checked==true)        {
       flag[6]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio7.length;i++){
     if(radio7.item(i).checked==true)        {
       flag[7]=i+1;
       total=total+1;
                  break;
       }
   }
   for(var i=0;i<radio8.length;i++){
     if(radio8.item(i).checked==true)        {
       flag[8]=i+1;
       total=total+1;
                  break;
       }
}
if(total!=10){alert("請選10個選項,少選剁了你")}
if(total==1){alert("少選9個選項")}
if(total==2){alert("少選8個選項")}
if(total==3){alert("少選7個選項")}
if(total==4){alert("少選6個選項")}
if(total==5){alert("少選5個選項")}
if(total==6){alert("少選4個選項")}
if(total==7){alert("少選3個選項")}
if(total==8){alert("少選2個選項")}
if(total==9){alert("少選1個選項")}

for(var i=1;i<11;i++)
{
if(flag[i]==1)
{a=a+1;}
}
for(var i=1;i<11;i++)
{
if(flag[i]==2)
{b=b+1;}
}
for(var i=1;i<11;i++)
{
if(flag[i]==3)
{c=c+1;}
}
drawChart()
}
function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['one',     a],
          ['two',      b],
          ['three',    c]
        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
</script>
</head>
<body>
   <form action="post.php" method="post"  name="add" enctype="multipart/form-data" onSubmit="return check();" >
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="1">1          
<input name="v1" type="radio" value="2">2            
<input name="v1" type="radio" value="3">3


<h1>2、ssss?</h1>
<input name="v2" type="radio" value="1">1        
<input name="v2" type="radio" value="2">2            
<input name="v2" type="radio" value="3">3

<h1>3、ssss?</h1>
<input name="v3" type="radio" value="1">1        
<input name="v3" type="radio" value="2">2            
<input name="v3" type="radio" value="3">3

<h1>4、ssss?</h1>
<input name="v4" type="radio" value="1">1        
<input name="v4" type="radio" value="2">2            
<input name="v4" type="radio" value="3">3

<h1>5、ssss?</h1>
<input name="v5" type="radio" value="1">1        
<input name="v5" type="radio" value="2">2            
<input name="v5" type="radio" value="3">3

<h1>6、ssss?</h1>
<input name="v6" type="radio" value="1">1        
<input name="v6" type="radio" value="2">2            
<input name="v6" type="radio" value="3">3

<h1>7、ssss?</h1>
<input name="v7" type="radio" value="1">1        
<input name="v7" type="radio" value="2">2            
<input name="v7" type="radio" value="3">3

<h1>8、ssss?</h1>
<input name="v8" type="radio" value="1">1        
<input name="v8" type="radio" value="2">2            
<input name="v8" type="radio" value="3">3

<h1>9、ssss?</h1>
<input name="v9" type="radio" value="1">1        
<input name="v9" type="radio" value="2">2            
<input name="v9" type="radio" value="3">3

<h1>10、ssss?</h1>
<input name="v10" type="radio" value="1">1        
<input name="v10" type="radio" value="2">2            
<input name="v10" type="radio" value="3">3
<input type="button" value="submit" onclick="check1()"/>
</form>
   <div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>

2016年4月29日 星期五

網頁選項









<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
 <Script type ="text/javascript">
</Script>

 <form action="#" method="post" class="demoForm" id="demoForm">
    <fieldset>
        <legend>Demo: Get Value of Selected</legend>
   
    <p>Select a shipping method:</p>
    <p>
        <label><input type="radio" name="ship" value="A" checked /> (A)Standard Ground</label>
        <label><input type="radio" name="ship" value="B" /> (B)Second Day</label>
        <label><input type="radio" name="ship" value="C" /> (C)Overnight</label>
        <label><input type="radio" name="ship" value="D" /> (D)Pick up</label>
    </p>
   
    <p><button type="button" name="getVal">Get Value of Selected</button></p>
   
    </fieldset>
</form>
<script type="text/javascript">
// to remove from global namespace
(function() {
   
    function getRadioVal(form, name) {
        var val;
        var radios = form.elements[name];
       
        for (var i=0, len=radios.length; i<len; i++) {
            if ( radios[i].checked ) {
                val = radios[i].value;
                break;
            }
        }
        return val;
    }


    document.forms['demoForm'].elements['getVal'].onclick = function() {
        alert( 'The selected radio button\'s value is: ' + getRadioVal(this.form, 'ship') );
    };
   
   
    // disable submission of all forms on this page
    for (var i=0, len=document.forms.length; i<len; i++) {
        document.forms[i].onsubmit = function() { return false; };
    }
   
}());
</script>

</body>
</html>

2016年4月21日 星期四

第一個APP


第四次上課

建立login.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `user`";
$result = $conn->query($sql);

if ($result != null) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["name"]. $row["passwd"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>