I have a long series of javascript functions that are invoked by 'onClick' on the function name in the html.
Corporate number <input type="text" autofocus id="corp_text">
<button onclick="getCorpNum(this.form)">SAVE</button><br><br>
LLC number <input type="text" autofocus id="LLC_text">
<button onclick="getLLCNum(this.form)">SAVE</button><br><br>
Type of nonprofit <input type="text" autofocus id="NP_text">
<button onclick="getNonProfit(this.form)">SAVE</button><br><br>
Other description <input type="text" autofocus id="OD_text">
<button onclick="getDesc(this.form)">SAVE</button><br><br>
In the javascript the functions are very similar in form:
/**
* Get corporation number text field data.
*/
var getCorpNum = function() {
var Corp_number = [];
Corp_number=document.getElementById("corp_text").value;
if (Corp_number.length > 0) createJSONobj("Corp", Corp_number);
}
/**
* Get LLC number text field data.
*/
var getLLCNum = function() {
var LLC_number = [];
LLC_number = document.getElementById("LLC_text").value;
if (LLC_number.length > 0) createJSONobj("LLC", LLC_number);
}
/**
* Get type of non-profit text field.
*/
var getNonProfit=function() {
var NP_number = [];
NP_number = document.getElementById("NP_text").value;
if (NP_number.length > 0) createJSONobj("NP", NP_number);
}
/**
* Get other description text
*/
var getDesc=function() {
var getDesc=[];
getDesc = document.getElementById("OD_text").value;
if (getDesc.length > 0) createJSONobj("Other_desc", getDesc);
}
The issue is that I have other functions like these that all have the same form and I'd would like to reduce the amount of code. Something generic that would capture the form of the code. This is difficult for me because the onClicks need the name of of each function object.