JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<title>PHP is Awesome!</title>
</head>
<body onload="setEventsInstance.addAllEvents()">
<div id = "fancyBackGround">
<form>
<select id = "xDropDown">
<option value = "test1">test1</option>
<option value = "test2">test2</option>
</select>
</form>
<button id="sendDataButton">ClickMe!</button>
<p id = "testOutput">not yet</p>
</div>
</body>
</html>
JavaScript
class userData {
catchDropDownSelection(){
this.dropDownSelection = $('#xDropDown').prop('selectedIndex');
console.log("dropDownSelection is ", this.dropDownSelection)
}
}
class sendData{
constructor(userData){
this.userDataClone = userData;
}
sendDropDownSelection(){
//this.userDataClone.catchDropDownSelection();
console.log("this.userDataClone.dropDownSelection inside sendDropDownSelection is ", this.userDataClone.dropDownSelection)
$.post("MyFirstPhP.php", {
userSelection : this.userDataClone.dropDownSelection
}, function (data){
//this.testFunction()
$('#testOutput').html(data);
//document.getElementById("testOutput").innerHTML = "data"
}).fail(function(){
console.log("$.post failed!");
})
}
testFunction(){
$('#testOutput').html("data");
}
}
class setEvents {
constructor(sendData, userData){
this.sendDataClone = sendData;
this.userDataClone = userData;
}
onClickEvents(){
$('#sendDataButton').click(function() {
this.userDataClone.catchDropDownSelection()
//console.log("index catched is ", this.sendDataClone.userDataClone.dropDownSelection)
}.bind(this));
$('#sendDataButton').click(function(){
this.sendDataClone.sendDropDownSelection()
}.bind(this))
}
addAllEvents(){
this.onClickEvents()
}
}
var userDataInstance = new userData();
var sendDataInstance = new sendData(userDataInstance);
var setEventsInstance = new setEvents(sendDataInstance, userDataInstance);