In this example we use Combo App to develop calculator app. Combo App use 3 files to develop an application. First is App File, 2nd Temp File for dynamic HTML and third one is SJS file for dynamic Java Script. Client side programming is also important when you need to develop more complex app. Combo App make this easy to create online software or AJAX base web apps View Demo
Application Code calculator.app
class calculator extends \Sphp\tools\ComboApp{
private $temp1 = null;
public function js_event_btn2_click($eventer) {
$val1 = $this->Client->request("val1");
$val2 = $this->Client->request("val2");
$this->JSServer->addJSONBlock("html","out2","Server Reply: " . ($val1 + $val2));
}
}
Front File calculator.front source code
<p>Type Two Number and Click on Submit Button, This will add two number on server and result back to client via ajax</p>
<div>Result is:
<div id="out2"></div>
</div>
<p><strong><br>Number1: <input id="txt1" type="text"><br>Number2: <input id="txt2" type="text"><br></strong></p>
<div>This Button Calculate with Java Script on Client Side<br><input id="btn1" type="button" value="Calculate Local"></div>
<p><strong> </strong></p>
<div>This Button Calculate with Java Script on Server Side<br><input id="btn2" type="button" value="Calculate Server JS"></div>
SJS File calculator.sjs source code
function ofjs_btn1_click(eventer){
let val1 = parseFloat($("#txt1").val());
let val2 = parseFloat($("#txt2").val());
$("#out2").html(val1 + val2);
}
function ofjs_btn2_click(eventer){
data["val1"] = parseFloat($("#txt1").val());
data["val2"] = parseFloat($("#txt2").val());
}