• No results found

Internet Ohjelmointi 1 Examples 4

N/A
N/A
Protected

Academic year: 2021

Share "Internet Ohjelmointi 1 Examples 4"

Copied!
11
0
0

Loading.... (view fulltext now)

Full text

(1)

Examples 4

Example 1

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Form</title> 5 </head> 6 <body>

7 <form method="post" action="calc.php">

8 Loan Amount <input type="text" name="principle" /><br> 9 Monthly Repayment <input type="text" name="monthly" /><br>

10 Number of Years <input type="text" name="years" value="25" /><br> 11 Interest Rate <input type="text" name="rate" value="6" /><br> 12 <input type="submit" value="SEND" /></form>

13 </body> 14 </html>

Example 2

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Margie's Travel</title>

5 <link rel="stylesheet" type="text/css" href="default.css"> 6 <style> 7 table {width: 100%} 8 body { 9 background-color: #cccc00; 10 } 11 </style> 12 </head> 13 <body> 14 <div id="header">

15 <h1 style="text-align: center; margin: 3px; font-size: 40px">Margie's Travel</h1>

16 <h5 style="text-align: center; margin: 5px; font-size: 16px">Leave the details to us, and leave your worries behind</h5> 17 </div>

18 <hr style="clear: left"> 19 <div id="main">

20 <h2>Sign Up for E-Mail Specials</h2> 21 <form method="post" action="handle.php"> 22 <table align="right" valign="top"> 23 <tr>

24 <td>Name:</td>

25 <td><input type="text" name="name" id="name" required autofocus></td>

26 </tr> 27 <tr>

28 <td>Address:</td>

29 <td><input type="text" name="address" required></td> 30 </tr>

(2)

33 <td><input type="text" name="city"></td> 34 </tr>

35 <tr>

36 <td>State:</td>

37 <td><input type="text" name="state"></td> 38 </tr>

39 <tr>

40 <td>ZIP:</td>

41 <td><input type="text" name="zip" required></td> 42 </tr>

43 <tr>

44 <td>E-mail address:</td>

45 <td><input type="email" name="email" maxlength="100" placeholder="Enter your email address"></td>

46 </tr> 47 <tr>

48 <td>Comments:</td>

49 <td><textarea name="comments" id="comments" rows="6" cols="50" placeholder="Enter comments here"></textarea></td>

50 </tr> 51 <tr>

52 <td></td>

53 <td><input type="submit" value="Submit" id="submit" onclick="show();">&nbsp

54 <input type="reset" value="Clear"></td> 55 </tr> 56 </table> 57 </form> 58 </div> 59 <div id="bottomnav"> 60 <hr style="clear: left"> 61 <p style="margin:0px; text-align:center"> 62 <a href="index.htm">Home</a> &nbsp;

63 <a href="domestic.htm">Domestic Travel</a> &nbsp; <a href="international.htm">International Travel</a> &nbsp;

64 <a href="faqs.htm">FAQs</a> &nbsp; 65 <a href="about.htm">About</a> &nbsp; 66 <a href="mailing.htm">Mailing List</a></p> 67 <hr>

68 </div> 69 <div>

70 <p class="copyright">

71 Copyright &copy; Margie's Travel<br>

72 No material may be reproduced without written permission<br> 73 <a href="mailto:[email protected]">Contact the Webmaster</a></p>

74 </div> 75 </body> 76 </html>

(3)

Examples 4

Example 21

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script> 5 function myFunction() 6 {

7 var coffee = document.getElementsByName("coffee"); 8 var txt = "";

9 var i;

10 for (i = 0; i < coffee.length; i++) 11 { 12 if (coffee[i].checked) 13 { 14 txt = txt + coffee[i].value + " "; 15 } 16 }

17 document.getElementById("order").value = "You ordered a coffee with: " + txt;

18 } 19 </script> 20 </head>

21 <body>

22 <p>How would you like your coffee?</p> 23 <form action="form_action.asp">

24 <input type="radio" name="coffee" value="cream">With cream<br> 25 <input type="radio" name="coffee" value="sugar">With milk<br> 26 <br>

27 <input type="button" onclick="myFunction()" value="Send order"> 28 <br><br>

29 <input type="text" id="order" size="50"> 30 <input type="submit" value="Submit"> 31 </form>

32 </body> 33 </html>

(4)

Example 22

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script> 5 function myFunction() 6 { 7 var x = document.getElementById("mySelect"); 8 var txt = "";

9 for (var i=0; i<x.length; i++) 10 { 11 if (x.options[i].selected) { 12 txt = txt + x.options[i].text + "<br>"; 13 } 14 } 15 document.getElementById("demo").innerHTML=txt; 16 } 17 </script> 18 </head> 19 <body> 20 21 <form>

22 <select id="mySelect" multiple="multiple"> 23 <option>Apple</option> 24 <option>Orange</option> 25 <option>Pineapple</option> 26 <option>Banana</option> 27 </select> 28 </form> 29

30 <p>Click the button to return the text of all options in the drop-down list.</p>

31

32 <p id="demo"></p> 33

34 <button type="button" onclick="myFunction()">Get the selected options</button> 35 36 37 38 </body> 39 </html>

(5)

Examples 4

Example 23

1 <!DOCTYPE html> 2 <!--

3 To change this license header, choose License Headers in Project Properties. 4 To change this template file, choose Tools | Templates

5 and open the template in the editor. 6 -->

7 <html> 8 <head>

9 <title>TODO supply a title</title> 10 <meta charset="ISO-8859-15">

11 <meta name="viewport" content="width=device-width"> 12 <script>

13 function show() {

14 var myradios = document.getElementsByName('gender');

15 for (var i = 0, length = myradios.length; i < length; i++) { 16 if (myradios[i].checked) {

17 myvalue = myradios[i].value;

18 break; //Because only one can be selected 19 } 20 } 21 window.alert(myvalue); 22 } 23 </script> 24 </head> 25 <body> 26 <form> 27 <label for="male">Male</label>

28 <input type="radio" name="gender" id="male" value="male"><br> 29 <label for="female">Female</label>

30 <input type="radio" name="gender" id="female" value="female"><br><br>

31 <input type="submit" value="Submit" onclick="show();"> 32 </form>

33 </body> 34 </html> 35

(6)

Example 3

1 <!DOCTYPE html> 2 <html>

3 <head>

4 <title></title>

5 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15"> 6 <style> 7 body { 8 width:100%; 9 } 10 form { 11 width:40%; 12 background-color: #ffcccc; 13 border: 1px solid; 14 } 15 h3 { 16 background-color: #009999; 17 width:40%; 18 color: #ffff00; 19 border: 1px solid; 20 } 21 </style> 22 </head> 23 <body>

24 <h3> Please answer the sports enquiry </h3> 25 <form action="do.php">

26 <fieldset> 27 <table>

28 <legend>Personal information</legend>

29 <tr><td><label for="name">Name</label></td>

30 <td><input type="text" name="name" value="" /> </td></tr> 31 <tr><td><label for="address">Address</label></td>

32 <td> <input type="text" name="address" value="" /> </td></tr> 33 <tr><td><label for="email">Email</label></td>

34 <td><input type="email" name="email" value="" /></td></tr> 35 <tr><td><label for="Male">Male</label> </td>

36 <td> <input type="radio" name="gender" value="Male" /></td></tr> 37 <tr><td><label for="Female">Female</label>

38 <td><input type="radio" name="gender" value="Female" /></td></tr> 39 40 </table> 41 </fieldset> 42 <fieldset> 43 <table> 44 <legend>Query</legend>

45 <tr><td><label for="sports">Select sports</label></td> 46 <tr><td><label for="tennis">Tennis</label></td>

47 <td><input type="checkbox" name="sports" value="tennis" /></td></tr> 48 <tr><td><label for="badminton">Badminton</label></td>

49 <td><input type="checkbox" name="sports" value="badminton" /> </td></tr> 50 <tr><td><label for="squash">Squash</label> </td>

51 <td> <input type="checkbox" name="sports" value="squash" /> </td></tr> 52 <tr><td><label for="gym">Gym</label></td>

53 <td><input type="checkbox" name="sports" value="gym" /></td></tr> 54 <tr><td><label for="usage">Usage</label></td></tr>

55 <tr><td><select name="usage" size="1">

56 <option value="daily">Daily</option> 57 <option value="weekly">Weekly</option> 58 <option value="monthly">Monthly</option>

59 <option value="morefreq">More frequently</option> 60 </select></td></tr> 61 </table> 62 </fieldset> 63 <fieldset> 64 <legend>Feedback</legend> 65 <label for="sat">Satisfaction</label>

66 1<input type="range" name="sat" min="1" max="100" step="1" value="1">100 67 <br><label id="label1" for="comment">Comments</label>

68 <textarea name="comment" cols="60" rows="5" wrap="hard"> Give free comments ...</textarea>

69 <hr>

70 <input type="submit" value="Submit"><input type="reset" value="Clear"> 71 </fieldset>

(7)

Examples 4

73 </body> 74 </html>

Example 4

1 <?php 2 3 $filename = "/tmp/myfile.txt";

4 $fp1 = fopen($filename ,"w") OR die("Can't open file"); 5 for($i=1; $i < 6;$i++) 6 { 7 fwrite($fp1,"<br>Row" . "$i"); 8 } 9 fclose($fp1); 10

11 $fp2 = fopen($filename ,"r") OR die("Can't open file"); 12 echo "<br><br>The contents of $filename file<br><br>"; 13 $filesize = filesize( $filename );

14 $filetext = fread( $fp2, $filesize ); 15 echo ( "File size : $filesize bytes" ); 16 echo ( "<pre>$filetext</pre>" ); 17 fclose( $fp2 ); 18 19 ?>

Example 5

1 <?php 2 3 $filename = "/tmp/myfile.txt";

4 $fp1 = fopen($filename ,"w") OR die("Can't open file"); 5 for($i=1; $i < 6;$i++) 6 { 7 fwrite($fp1,"<br>Row" . "$i"); 8 } 9 fclose($fp1); 10

11 $fp2 = fopen($filename ,"r") OR die("Can't open file"); 12 echo "<br><br>The contents of $filename file<br><br>"; 13 $filesize = filesize( $filename );

14 while(!feof($fp2)) { 15 $line = fgets($fp2); 16 echo $line;

17 }

18 echo ( "<br>File size : $filesize bytes" ); 19 echo ( "<pre>$filetext</pre>" );

20 fclose( $fp2 ); 21

(8)

Example 6

1 <?php

2 $hak = opendir("images/"); 3 $nimi = readdir($hak);

4 echo "<br><br><br><br>Directory Images/"; 5 while ($nimi) { 6 echo "<br>$nimi\n"; 7 $nimi = readdir($hak); 8 } 9 closedir($hak); 10 ?>

Example 7

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title>

5 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15"> 6 <style> 7 form { 8 width:40%; 9 background-color: #ffcccc; 10 border: 1px solid; 11 } 12 h3 { 13 background-color: #009999; 14 width:40%; 15 color: #ffff00; 16 border: 1px solid; 17 } 18 </style> 19 <script type="text/javascript"> 20 function clearStatus() { 21 document.getElementById("status").innerHTML = ""; 22 } 23 function sendData(event) 24 { 25 var gender;

26 var myname = document.getElementById("myname").value; 27 var address = document.getElementById("address").value; 28 var email = document.getElementById("email").value; 29 var age = document.getElementById("age").value; 30 var radios = document.getElementsByName('gender');

31 for (var i = 0, length = radios.length; i < length; i++) { 32 if (radios[i].checked) { 33 gender = radios[i].value; 34 break; 35 } 36 } 37 if (window.XMLHttpRequest)

38 {// code for IE7+, Firefox, Chrome, Opera, Safari 39 xmlhttp=new XMLHttpRequest();

40 } 41 else

42 {// code for IE6, IE5

43 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 44 }

45 xmlhttp.onreadystatechange=function() 46 {

47 if (xmlhttp.readyState==4 && xmlhttp.status==200) 48 {

49 document.getElementById("status").innerHTML=xmlhttp.responseText; 50 }

51 }

52 xmlhttp.open("GET","saveData.php?name="+myname + "&address=" +address + "&email=" +email +

53 "&age=" +age + "&gender=" +gender,true); 54 xmlhttp.send();

(9)

Examples 4

56 </script> 57 </head> 58 <body>

59 <h3> Please enter the fields and submit </h3> 60 <form>

61 <fieldset> 62 <table>

63 <legend>Personal information</legend>

64 <tr><td><label for="name">Name</label></td>

65 <td><input type="text" name="myname" id="myname" value="" /> </td></tr> 66 <tr><td><label for="address">Address</label></td>

67 <td> <input type="text" name="address" id="address" value="" /> </td></tr>

68 <tr><td><label for="email">Email</label></td>

69 <td><input type="email" name="email" id="email" value="" /></td></tr> 70 <tr><td><label for="Male">Male</label> </td>

71 <td> <input type="radio" name="gender" id="male" value="Male" /></td></tr>

72 <tr><td><label for="Female">Female</label></td>

73 <td><input type="radio" name="gender" id="female" value="Female" /></td></tr>

74 <tr><td><label for="age">Age: </label></td>

75 <td> <input id="age" type="number" min="0" max="120" step="1" value ="21"/></td></tr>

76 </table> 77 <hr>

78 <input id="submit" type="button" value="Submit" onclick="sendData();"><input type="reset" value="Clear" onclick="clearStatus();" >

79 <div id="status"></div> 80 </fieldset> 81 </form> 82 </body> 83 </html> saveData.php 1 <?php 2 error_reporting(E_ALL); 3 ini_set('display_errors', '1'); 4 $name=$_GET["name"]; 5 $address=$_GET["address"]; 6 $email=$_GET["email"]; 7 $age=$_GET["age"]; 8 $gender=$_GET["gender"]; 9 $filename = "/tmp/persons6.txt"; 10 $fp1 = fopen($filename ,"a"); 11 if($fp1) { 12 if(filesize($filename) == 0) 13 fwrite($fp1, "<tr><th>Name</th><th>Address</th><th>Age</th><th>Email</th><th>Gender</th></tr> \r\n");

14 fwrite($fp1, "<tr><td>" . $name . "</td><td>" . $address . "</td><td>" . $age ."</td><td>" . $email .

15 "</td><td>" . $gender . "</tr>\r\n"); 16 $status = "Save succesfull";

17 } 18 else

19 $status = "Save not succesfull"; 20 fclose($fp1);

21 echo $status; 22 ?>

(10)

Example 8

1 <!DOCTYPE html> 2 <html>

3 <head>

4 <title></title>

5 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15"> 6 <style> 7 table { 8 width:40%; 9 } 10 table, td, th{ 11 border: solid 2px; 12 background-color: #ffcccc; 13 } 14 </style> 15 <script type="text/javascript"> 16 function getData(event) 17 { 18 if (window.XMLHttpRequest)

19 {// code for IE7+, Firefox, Chrome, Opera, Safari 20 xmlhttp=new XMLHttpRequest();

21 } 22 else

23 {// code for IE6, IE5

24 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 25 }

26 xmlhttp.onreadystatechange=function() 27 {

28 if (xmlhttp.readyState==4 && xmlhttp.status==200) 29 { 30 document.getElementById("data").innerHTML=xmlhttp.responseText; 31 } 32 } 33 xmlhttp.open("GET","getData.php",true); 34 xmlhttp.send(); 35 } 36 </script> 37 </head> 38 <body>

39 <h3> Please press button to get data </h3>

40 <input id="fetch" type="button" value="Get data" onclick="getData();"> 41 <div id="data"></div> 42 </body> 43 </html> getData.php 1 <?php 2 $filename = "/tmp/persons6.txt";

3 $fp2 = fopen($filename ,"r") OR die("Can't open file"); 4 $filesize = filesize( $filename );

5 $filetext = fread( $fp2, $filesize ); 6 fclose( $fp2 );

7 echo ( "<table>$filetext</table>" ); 8 ?>

(11)

Examples 4

Example 9

1 <!DOCTYPE html> 2 <html>

3 <head>

4 <title>PHP Form Upload</title> 5 </head>

6 <body>

7 <form action="upload.php" method="post" enctype="multipart/form-data">

8 <label for="file">Filename:</label>

9 <input type="file" name="file" id="file"><br> 10 <input type="submit" name="submit" value="Submit"> 11 </form>

12 </body> 13 </html>

upload.php: 1 <?php

2 $allowedExts = array("JPG", "jpg", "jpeg", "gif", "png"); 3 $extension = end(explode(".", $_FILES["file"]["name"])); 4 if ((($_FILES["file"]["type"] == "image/gif")

5 || ($_FILES["file"]["type"] == "image/jpeg") 6 || ($_FILES["file"]["type"] == "image/png") 7 || ($_FILES["file"]["type"] == "image/pjpeg")) 8 && ($_FILES["file"]["size"] < 20000)

9 && in_array($extension, $allowedExts)) 10 {

11 if ($_FILES["file"]["error"] > 0) 12 {

13 echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; 14 }

15 else 16 {

17 echo "Upload: " . $_FILES["file"]["name"] . "<br>"; 18 echo "Type: " . $_FILES["file"]["type"] . "<br>";

19 echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; 20 echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; 21

22 if (file_exists("/home/user/" . $_FILES["file"]["name"])) 23 {

24 echo $_FILES["file"]["name"] . " already exists. "; 25 }

26 else 27 {

28 move_uploaded_file($_FILES["file"]["tmp_name"], 29 "/home/user/images/" . $_FILES["file"]["name"]);

30 echo "Stored in: " . "/home/user/" . $_FILES["file"]["name"]; 31 }

32 } 33 } 34 else 35 {

36 echo "Invalid file"; 37 }

References

Related documents

A process was developed to identify potential defects in previous layers of Selective Laser Melting (SLM) Powder Bed Fusion (PBF) 3D printed metal parts using a mid-IR thermal camera

Als we de voorgaande hoofdstukken goed hebben bestudeerd en door veel oefenen de nodige vaardigheid hebben gekregen, moeten we nu in staat zijn, een vakkundige tekening te maken.

Make  changes  to  section  on  agreements  to   reflect  emphasis  of  agreements  in  new

shapes of the AGN and star formation IR SEDs (see blue dashed and red solid curves in Fig. 2 ), which results in sources with a signif- icant contribution from the AGN component

In just 9 months of part-time classes at Shillington, I was able to conceptualise and design my very first cookbook which was published by Random House in 2014.” SNEH ROY IS A

Political Parties approved by CNE to stand in at least some constituencies PLD – Partido de Liberdade e Desenvolvimento – Party of Freedom and Development ECOLOGISTA – MT –

This model posits four types of health beliefs that affect an individual’s health behavior, in this case, the decision to seek mental health services: perceived

• Taxpayers subject to the provisions of Title II of the Income Tax Law (ITL) which have declared taxable income of $644,599,005 or more in the immediately preceding tax