JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/icon.css">
<script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script>
$.fn.textbox.defaults = $.extend({},$.fn.textbox.defaults,{
inputEvents:$.extend({},$.fn.textbox.defaults.inputEvents,{
keydown:function(e){
if(e.keyCode == 27){
var target = e.data.target;
var v = $(target).textbox('getValue');
$(target).textbox('initValue', v);
//$(target).textbox('reset');
}
}
})
});
var selEmp = null;
var emp1Add = ['Alsterpark','Hamburg','22048'];
var emp2Add = ['Bill street','Munich','52874'];
function showAddress(emp) {
if(emp == "emp1") {
selEmp = 'emp1';
$('#streetTB').textbox('initValue', emp1Add[0]);
$('#cityTB').textbox('initValue', emp1Add[1]);
$('#pcTB').textbox('initValue', emp1Add[2]);
} else if(emp == "emp2") {
selEmp = 'emp2';
$('#streetTB').textbox('initValue', emp2Add[0]);
$('#cityTB').textbox('initValue', emp2Add[1]);
$('#pcTB').textbox('initValue', emp2Add[2]);
} else{
selEmp = null;
}
}
</script>
<div id="empListDiv">
<a href="#" onclick="javascript:showAddress('emp1');">Employee1</a><br>
<a href="#" onclick="javascript:showAddress('emp2');">Employee2</a>
<p><p>
</div>
<div id="addressDiv">
Street: <input id="streetTB">
City: <input id="cityTB">
Postcode:<input id="pcTB">
</div>
JavaScript
function saveAddress(pos, value) {
if(selEmp == 'emp1') {
emp1Add[pos] = value;
} else if(selEmp == 'emp2') {
emp2Add[pos] = value;
}
}
$(function(){
$('#streetTB').textbox({
width: 150,
onChange: function(newValue, oldValue) {
saveAddress(0, newValue);
}
});
$('#cityTB').textbox({
width: 100,
onChange: function(newValue, oldValue) {
saveAddress(1, newValue);
}
});
$('#pcTB').textbox({
width: 60,
required:true,
validType:'length[5,5]',
onChange: function(newValue, oldValue) {
saveAddress(2, newValue);
}
});
});