-
Notifications
You must be signed in to change notification settings - Fork 0
/
playingwjs.html
62 lines (50 loc) · 1.84 KB
/
playingwjs.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
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div>
<a href="javascript:Connect()">Click to connect to mood tracker</a>
</div>
<!--Trying out input stuff-->
<p>Workie workie? <input type="text" id="inputText" value="Type something here" /></p>
<button onclick="grabtext()">Workie?</button>
<p id="whatthe"></p>
<div>
<p>And for anumber? <input id="mood" type="number" min="1" max="5" onchange="grabmood()"></p>
<button>testing</button>
<p id="moodwhatthe"></p>
</div>
<script>
//trying to make something work
function grabtext()
{
var x = document.getElementById("inputText").value;
document.getElementById("whatthe").innerHTML=x
}
function grabmood()
{
var x = document.getElementById("mood").value;
document.getElementById("moodwhatthe").innerHTML = x;
console.log("JSON string is: " + JSON.stringify(x));
// SendMood(x)
}
//check if browser supports websockets
function SendMood(x)
{
//create a WebSocket and open it
var connection = new WebSocket("ws://mood.gretaparks.com");
connection.onopen = function (x)
{
connection.send(JSON.stringify(x))
console.log("confirm sent JSON string :" + JSON.stringify)
}
connection.close();
}
// function TestSocket(){if ("WebSocket" in window) {run stuff....} else{alert("WebSocket is not supported by your browser")}
// For error handling:connection.onerror = function() <-- add stuff {console.log("Error" + Error)}
</script>
</body>
</html>