forked from EddwaardHaar/Group_8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajaxlomake.html
55 lines (49 loc) · 1.63 KB
/
ajaxlomake.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<body>
<script>
function lahetaKala(lomake){
var kala=new Object();
kala.id=lomake.id.value;
kala.laji=lomake.laji.value;
kala.paino=lomake.paino.value;
var jsonKala=JSON.stringify(kala);
jsonKentta.innerHTML=jsonKala;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("result").innerHTML = this.responseText;
}
};
xmlhttp.open("POST", "./lisaakala.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("kala=" + jsonKala);
}
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("muokattava").innerHTML = this.responseText;
kala=JSON.parse(this.responseText);
kalalomake.laji.value=kala.laji;
kalalomake.paino.value=kala.paino;
}
};
xmlhttp.open("GET", "./haekalat.php?muokattava="+indeksi , true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
</script>
<h2>Fill in!</h2>
<form id='kalalomake'>
ID: <input type='text' name="id" value=" " placeholder="id" readonly><br>
Laji: <input type='text' name='laji' value='' placeholder='kalan laji...'><br>
Paino: <input type='text' name='paino' value='' placeholder='kalan paino...'><br>
<input type='button' name='ok' value='Lähetä' onclick='lahetaKala(this.form);'><br>
</form>
<button onclick="haeKalat();">Hae kalat</button>"
<div id='muokattava'></div>
muokattava kala tähän
<div id='result'>
Palaute tähän
</div>
<div id='jsonkentta'>
Palaute tähän
</div>
</body>