[Solved] How to insert data text field [number datatype] to database using javascript

Newbie Salesforce Asks: How to insert data text field [number datatype] to database using javascript
below is my interface. My question is when the user insert a number in the field, may I know how to posh it to the database?


enter image description here

Here is my code

Code:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}

var result = sforce.connection.query("SELECT Id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId='{!CreditLimit__c.Id}'");
var approvals = result.getArray("records");

try{
jQuery(function() {
/*Append the jQuery CSS CDN Link to the Head tag.*/
jQuery('head').append('<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.css" type="text/css" />');

/*Create the HTML(DIV Tag) for the Dialog.*/
var html = '<div id="dialog" title="Final Approval?"><p>Please confirm if this is FINAL APPROVAL</p><p>Approved Amount [USD]: </p><input type="number" id = Amount value= {!CreditLimit__c.Approved_Amount__c} size="30" name="Amount"></div>';



/*Check if the Dialog(DIV Tag) already exists if not then Append the same to the Body tag.*/
if(!jQuery('[id=dialog]').size()){
jQuery('body').append(html);
}

/*Open the jQuery Dialog.*/
jQuery( "#dialog" ).dialog({
autoOpen: true,
modal: true,
show: {
effect: "",
duration: 000
},
hide: {
effect: "",
duration: 000
},

buttons: {
"Yes": function() {
if(approvals != undefined && approvals.length > 0){

var newRecords = [];
var L = new sforce.SObject("CreditLimit__c");
L.id ="{!CreditLimit__c.Id}";
L.Final_Approved__c = true;
newRecords.push(L);
results = sforce.connection.update(newRecords);
window.location.reload();
var approvalID = approvals[0].Id;
window.open('/p/process/ProcessInstanceWorkitemWizardStageManager?id='+approvalID,'_self');


//window.open('/p/process/ProcessInstanceWorkitemWizardStageManager?id='+approvalID,'_self');
}
else{
alert("There are no approvals pending.")
}
},
"No": function() {
//var result = sforce.connection.query("SELECT Id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId='{!CreditLimit__c.Id}'");
//var approvals = result.getArray("records");
if(approvals != undefined && approvals.length > 0){
var newRecordsfalse = [];
var L = new sforce.SObject("CreditLimit__c");
L.id ="{!CreditLimit__c.Id}";
L.Final_Approved__c = false;
newRecordsfalse.push(L);
results = sforce.connection.update(newRecordsfalse);
window.location.reload();
var approvalID = approvals[0].Id;
window.open('/p/process/ProcessInstanceWorkitemWizardStageManager?id='+approvalID,'_self');
}
else{
alert("There are no approvals pending.")
}
}
}
});
});
}
catch(e){
alert('An Error has Occured. Error: ' + e);
}

This code is to let users insert value, but I don’t know how to insert value by user to database

Code:
var html = '<div id="dialog" title="Final Approval?"><p>Please confirm if this is FINAL APPROVAL</p><p>Approved Amount [USD]: </p><input type="number" id = Amount value= {!CreditLimit__c.Approved_Amount__c} size="30" name="Amount"></div>';

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.