This lesson describes code for updating and deleting rows.
Add the Update function to tutorial.js:
function Update() { var id; try { CustomerTable.updateBegin(); id = CustomerTable.schema.getColumnID("fname"); CustomerTable.setString(id, Cust_FName); id = CustomerTable.schema.getColumnID("lname"); CustomerTable.setString(id, Cust_LName); id = CustomerTable.schema.getColumnID("city"); if( Cust_City.length > 0 ) { CustomerTable.setString(id, Cust_City); } else { CustomerTable.setNull(id); } id = CustomerTable.schema.getColumnID("phone"); if( Cust_Phone.length > 0 ) { CustomerTable.setString(id, Cust_Phone); } else { CustomerTable.setNull(id); } CustomerTable.update(); } catch( ex ) { alert( "Update error: " + ex.getMessage() ); } }
Add the Delete function to tutorial.js:
function Delete() { if( CustomerTable.getRowCount() == 0 ) { return; } CustomerTable.deleteRow(); CustomerTable.moveRelative(0); }
Add the following functions to main.html:
function ClickUpdate() { FetchForm(); Update(); DisplayCurrentRow(); } function ClickDelete() { Delete(); DisplayCurrentRow(); }
Synchronize your M-Business Client and run the application.