I have an application that is sending a variable to another system which requires the variable to be 16 characters. However, the user is not required to enter a 16 digit number.
Here is the coding I have so far:
Within the file to activate the javascript:
<A HREF="javascript:onClick=creditlink()" title="Enter own credit memo number.">Create Credit Memo</a>
Here is the javascript I am using:
function creditlink ()
{
var cmnum2 = document.getElementById('creditmemo').value;
var cmnum = document.getElementById('autocmnum').value;
var clmid = document.getElementById('claimid').value;
//alert (cmnum);
if (cmnum2) {
window.open("https://somewebpage.cfm?creditmemos=" + cmnum2 + "&claimid=" +clmid );
}
//This is the customer did not want to enter their own number one would be auto generated
else {
window.open("https://somewebpage.cfm?creditmemos=" + cmnum + "&claimid=" +clmid );
}
}
So here where I need help for cmnum2 I need it to be turned into 16 characters before it is sent in the link. FYI this function is working great.
So my thought was to just add space padding before the value to equal 16characters. Here is a example of what I need:
User enter: cmnum2 = "61150331" (8 characters) New value: cmnum2 = "(8 spaces)61150331" (total 16 characters with spaces)
I believe I have seen it done with functions like string.format or string padleft or padright but I am not sure how the coding format would work to make it 16 no matter what the value is.