I have a function that sums my values and everything works fine, but only when all inputs have a value entered. However, I would like default to have 0 assigned to it.so that the function works when at least one value is given . How to do it ?.
var DeductiblepercentageM = thisPointer.entity.getValue('number.DeductiblepercentageM[' + i + ']');
var InsuranceLimitM = thisPointer.entity.getValue('number.InsuranceLimitM[' + i + ']');
var insuranceRaitingM = thisPointer.entity.getValue('number.insuranceRaitingM[' + i + ']');
var InsurerNumberM = thisPointer.entity.getValue('number.InsurerNumberM[' + i + ']');
DeductiblepercentageM = DeductiblepercentageM.replace(",", ".");
DeductiblepercentageM = parseFloat(DeductiblepercentageM)
InsuranceLimitM = InsuranceLimitM.replace(",", ".");
InsuranceLimitM = parseFloat(InsuranceLimitM)
insuranceRaitingM = insuranceRaitingM.replace(",", ".");
insuranceRaitingM = parseFloat(insuranceRaitingM)
InsurerNumberM = InsurerNumberM.replace(",", ".");
InsurerNumberM = parseFloat(InsurerNumberM)
//log the outcome of decimal separator change
var positionSum = +(DeductiblepercentageM + InsuranceLimitM +insuranceRaitingM + InsurerNumberM);
jQ('[id="DeductibleM[' + i + ']"]').val(positionSum);
thisPointer.entity.setValue('DeductibleM[' + i + ']', positionSum);
thisPointer.entity.mergeLocal(true);
if (totalSum != "NaN") {
totalSum = +(totalSum + positionSum).toFixed();
}
}
else {
totalSum = "-";
}
According to #Terry
var InsuranceLimitM = thisPointer.entity.getValue('number.InsuranceLimitM[' + i + ']') || 0;
adding || 0 to the end of the code helps and makes the code count right away
General View
https://docs.google.com/spreadsheets/d/e/2PACX-1vSNW9Gibu5OSFs7Os73vbfwtloJnyw4PnzPLs9IXGzDSshC2Y10jxKHChDYpScJTfHf2viqAADwPmya/pubhtml
after editing previous code thanks to theMaster now I have:
function layout_inc() {
var semanal = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Semanal');
semanal.getRange('D4').clearcontent;
var rangoEmpleados = semanal.getRange(3, 1, semanal.getLastRow() - 2, 10).getDisplayValues();
var ly_inc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Layout_incidencias');
ly_inc.clearContents();
var rangely_inc = ly_inc.getRange(1, 1, rangoEmpleados.length, 1);
for (let i = 0; i < rangoEmpleados.length; i++) {
var innerArrayLength = rangoEmpleados[i].length;
for (let j = 3; j < innerArrayLength; j++) {
let outputArray = [];
if (rangoEmpleados[i][j] == 'F') {
outputArray = '"' + rangoEmpleados[i][0] + '"' + ',' + rangoEmpleados[0][j] + ',' + ',' + '"F"' + "," + '""' + "," + '""' + "," + '""'
rangely_inc.setValue(outputArray);
SpreadsheetApp.flush()
Logger.log(outputArray);
} else if (rangoEmpleados[i][j] == 'V') {
var v = [ '"' + rangoEmpleados[i][0] + '"' + "," + rangoEmpleados[0][j] + '""' + ',' + '"V"' + "," + '""' + "," + '""' + "," + '""'];
}
}
}
}
So in order to create a new array that shows the emp_id (A4:A), date(C3:I3) and a string "F", if and only if theres an F where there isnt any clockin/out movement, Im trying to setvalues in a different sheet and that sheet will be a csv later. But, setValue will only return a string, the very first one and duplicate it trough the entire array. yet
Logger.log(outputArray); it does show the new array how I want it, I just need to set it in the other sheet.
4:19:22 AM Info "547",20/06/2022,,"F","","",""
4:19:23 AM Info "855",17/06/2022,,"F","","",""
4:19:23 AM Info "855",18/06/2022,,"F","","",""
4:19:23 AM Info "855",20/06/2022,,"F","","",""
4:19:24 AM Info "855",21/06/2022,,"F","","",""
4:19:24 AM Info "855",22/06/2022,,"F","","",""
4:19:24 AM Info "855",23/06/2022,,"F","","",""
but:
rangely_inc.setValue(outputArray);
returns:
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
"507",18/06/2022,,"F","","",""
Treat the data as an array.
Every spreadsheet in Google Sheets is treated as a 2D array. In this solution, I introduced a secondary output variable out2 and pushed the desired outputs into it. Afterwards, I declared the rangely_inc variable last so that its range may adjust dynamically to the size of out2. With that, there will then be no issues in using the .setValues() function.
function layout_inc() {
var semanal = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Semanal');
semanal.getRange('D4').clearcontent;
var rangoEmpleados = semanal.getRange(3, 1, semanal.getLastRow() - 2, 10).getDisplayValues();
var ly_inc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Layout_incidencias');
ly_inc.clearContents();
var outputArray = [];
var out2 = [];
for (let i = 0; i < rangoEmpleados.length; i++) {
var innerArrayLength = rangoEmpleados[i].length;
for (let j = 3; j < innerArrayLength; j++) {
if (rangoEmpleados[i][j] == 'F') {
outputArray= ['"' + rangoEmpleados[i][0] + '"' + ',' + rangoEmpleados[0][j] + ',' + ',' + '"F"' + "," + '""' + "," + '""' + "," + '""'];
out2.push(outputArray);
} else if (rangoEmpleados[i][j] == 'V') {
var v = ['"' + rangoEmpleados[i][0] + '"' + "," + rangoEmpleados[0][j] + '""' + ',' + '"V"' + "," + '""' + "," + '""' + "," + '""'];
}
}
}
var rangely_inc = ly_inc.getRange(1,1, out2.length, 1);
rangely_inc.setValues(out2);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm running a web page in Safar, however; I notice that when I press the save button the event doesn't fire. It works fine in IE though. I've researched the issue, and found that it's not due to a missing value attribute or single/double quote specifics. Any help would be appreciated.
<input type='button' name='Save' id='saveCut' value='Save Cut' class=button onClick=\"Puma.saveTheCut()\">
JS function
Puma.saveTheCut = function () {
var offerId = inStoreCut.cutOfferFields[0];
var merchId = inStoreCut.cutOfferFields[1];
var adId = inStoreCut.cutOfferFields[2];
var eventID = inStoreCut.cutOfferFields[3];
var adNum = inStoreCut.cutOfferFields[4];
var cutID = inStoreCut.cutOfferFields[5];
var merchDescription = parent.main.document.getElementById('merchDescription').value;
var UPC = parent.main.document.getElementById('merchUPC').value;
var nrfSampleColorObj = parent.main.document.getElementById('itemColor');
var nrfSampleColor = nrfSampleColorObj.options[nrfSampleColorObj.selectedIndex].value;
var nrfsampleSubColorObj = parent.main.document.getElementById('itemChildColor');
var colorCodeStr = nrfsampleSubColorObj.options[nrfsampleSubColorObj.selectedIndex].value;
var nrfsampleSubColor = colorCodeStr.substring(0, 3);
var customer_Facing_Color = parent.main.document.getElementById('merchCustomerFacingColor').value;
var division = parent.main.document.getElementById('merchFob').value;
var deptNum = parent.main.document.getElementById('merchDept0~0').value;
var vendorNum = parent.main.document.getElementById('merchVendorNum0~0').value;
var pID = parent.main.document.getElementById('pID0~0').value;
var regPrice = parent.main.document.getElementById('regPrice').value;
var sampleSize = parent.main.document.getElementById('itemSize').value;
var itemQty = parent.main.document.getElementById('itemQty').value;
if (parent.main.document.getElementById('chkMerchSet').checked) {
var set = "1";
}
else {
var set = "0";
}
var sampleTypeObj = parent.main.document.getElementById("itemType");
var sampleType = sampleTypeObj.options[sampleTypeObj.selectedIndex].text;
var merchColorCorrObj = parent.main.document.getElementById("merchColorCorr");
var colorCorr = merchColorCorrObj.options[merchColorCorrObj.selectedIndex].value;
var merchSwatchObj = parent.main.document.getElementById("merchSwatch");
var Swatch = merchSwatchObj.options[merchSwatchObj.selectedIndex].value;
var pantoneColor = parent.main.document.getElementById('merchPantone').value;
var photoStylingDetails = parent.main.document.getElementById('merchPhotoStylingDetails').value;
var mCOMSampleId = parent.main.document.getElementById('mCOMSample').value;
var deptName = parent.main.document.getElementById('merchDeptName0~0').innerHTML;
var vendorName = Puma.decoder(parent.main.document.getElementById('merchVendorName0~0').innerHTML);
if (parent.main.document.getElementById('pidStatus0~0').value == "NOT IN PD") {
var pidStatus = "0";
}
else {
var pidStatus = "1";
}
var pidDescription = parent.main.document.getElementById('pidDescription').value;
var webId = parent.main.document.getElementById('webID0~0').innerHTML;
var vStyle = parent.main.document.getElementById('merchVStyle').value;
var markStyle = parent.main.document.getElementById('merchMarkStyle').value;
var subClass = parent.main.document.getElementById('Subclass').value;
// var productDescription = parent.main.document.getElementById('productDescription').value;
var docLineitemNum = parent.main.document.getElementById('merchDoc').value;
var merchTurnInStatusObj = parent.main.document.getElementById("merchTurnInStatus");
var turnInStatus = merchTurnInStatusObj.options[merchTurnInStatusObj.selectedIndex].text;
var reason = parent.main.document.getElementById('merchReason').value;
var merchCountryOriginObj = parent.main.document.getElementById("countryOfOrigin");
var countryOfOrigin = merchCountryOriginObj.options[merchCountryOriginObj.selectedIndex].value;
var importedCountry = parent.main.document.getElementById("importedCountries").value;
//var importedCountry = merchImportedCountryObj.options[merchImportedCountryObj.selectedIndex].text;
var fabricContent = parent.main.document.getElementById("fabricContent").value;
var careInstructions = parent.main.document.getElementById("careInstructions").value;
var offerDescription = parent.main.document.getElementById("offerDescription").value;
var onlyAtMacysObj = parent.main.document.getElementById("onlyAtMacys");
var onlyAtMacysValue = parseInt(onlyAtMacysObj.options[onlyAtMacysObj.selectedIndex].value, 10);
var onlyAtMacys = onlyAtMacysValue;
var legalOneObj = parent.main.document.getElementById("legalOne");
var legalOne = legalOneObj.options[legalOneObj.selectedIndex].value;
var legalOneExplain = parent.main.document.getElementById("explainLegalOne").value;
var legalTwoObj = parent.main.document.getElementById("legalTwo");
var legalTwo = legalTwoObj.options[legalTwoObj.selectedIndex].value;
var legalTwoExplain = parent.main.document.getElementById("explainLegalTwo").value;
var legalThreeObj = parent.main.document.getElementById("legalThree");
var legalThree = legalThreeObj.options[legalThreeObj.selectedIndex].value;
var legalThreeExplain = parent.main.document.getElementById("explainLegalThree").value;
var legalFourObj = parent.main.document.getElementById("legalFour");
var legalFour = legalFourObj.options[legalFourObj.selectedIndex].value;
var fiftyObj = parent.main.document.getElementById("overFifty");
var fifty = fiftyObj.options[fiftyObj.selectedIndex].value;
var userId = parent.botnav.uinfo.userID;
if (Puma.btiRequiredFieldIsValidated() == true) {
if (inStoreCut.existingRecord == false) {
sql = "action=saveMerchFormForCut&cutID=" + cutID +
//sql = "action=updateMerchFormForCut&cutID=" + cutID +
"&merchDescription=" + encodeURIComponent(merchDescription) +
"&UPC=" + UPC +
"&nrfSampleColor=" + nrfSampleColor +
"&nrfSampleSubColor=" + nrfsampleSubColor +
"&division=" + encodeURIComponent(division) +
"&deptNum=" + deptNum +
"&merchVendorNum=" + vendorNum +
"&pID=" + pID +
"&Customer_Facing_Color=" + encodeURIComponent(customer_Facing_Color) +
"®Price=" + regPrice +
"&sampleSize=" + encodeURIComponent(sampleSize) +
"&itemQty=" + itemQty +
"&set=" + set +
"&sampleType=" + sampleType +
"&colorCorr=" + colorCorr +
"&Swatch=" + Swatch +
"&pantoneColor=" + encodeURIComponent(pantoneColor) +
"&photoStylingDetails=" + encodeURIComponent(photoStylingDetails) +
"&mCOMSampleId=" + mCOMSampleId +
"&deptName=" + deptName +
"&vendorName=" + encodeURIComponent(vendorName) +
"&pidStatus=" + pidStatus +
"&pidDescription=" + pidDescription +
"&webId=" + webId +
"&vStyle=" + vStyle +
"&markStyle=" + markStyle +
"&subClass=" + subClass +
"&docLineItemNum=" + docLineitemNum +
"&merchTurnInStatus=" + turnInStatus +
"&reason=" + encodeURIComponent(reason) +
"&countryOfOrigin=" + countryOfOrigin +
"&importedCountry=" + importedCountry +
"&fabricContent=" + encodeURIComponent(fabricContent) +
"&careInstructions=" + encodeURIComponent(careInstructions) +
"&offerDescription=" + encodeURIComponent(offerDescription) +
"&onlyAtMacys=" + onlyAtMacys +
"&legalOne=" + legalOne +
"&legalOneExplain=" + legalOneExplain +
"&legalTwo=" + legalTwo +
"&legalTwoExplain=" + legalTwoExplain +
"&legalThree=" + legalThree +
"&legalThreeExplain=" + legalThree +
"&legalFour=" + legalFour +
"&fifty=" + fifty +
"&createdBy=" + userId
var ajaxMaster = new AjaxMaster(sql, "Puma.saveMerchFormForCutData(data)", "", "btiDispatcher.aspx");
sql = "action=updateMerchFormForCut&sql=" + encodeURIComponent(msql);
objAjaxAd.main_flag = "updateMerchFormForCut";
objAjaxAd.SendQuery(sql);
// "[t0].[signedByUserID]," +
// "[t0].[signedStatus]," +
//"[t0].[dateSigned]," +
//"[t0].[signedLastByUserID]," +
//"[t0].[dateLastSigned1]," +
//"[t0].[signedLastStatus]" +
// var ajaxMaster = new AjaxMaster(sql, "Puma.updateMerchFormForCutData(data)", "", "puma_core.aspx");
}
else {
sql = "action=updateMerchFormForCut&cutID=" + cutID +
"&offerId" + offerId +
"&merchId" + merchId +
"&adID" + adId +
"&eventID" + eventID +
"&adNum" + adNum +
"&merchDescription=" + encodeURIComponent(merchDescription) +
"&UPC=" + UPC +
"&nrfSampleColor=" + nrfSampleColor +
"&nrfSampleSubColor=" + nrfsampleSubColor +
"&division=" + encodeURIComponent(division) +
"&deptNum=" + deptNum +
"&merchVendorNum=" + vendorNum +
"&pID=" + pID +
"&Customer_Facing_Color=" + encodeURIComponent(customer_Facing_Color) +
"®Price=" + regPrice +
"&sampleSize=" + encodeURIComponent(sampleSize) +
"&itemQty=" + itemQty +
"&set=" + set +
"&sampleType=" + sampleType +
"&colorCorr=" + colorCorr +
"&Swatch=" + Swatch +
"&pantoneColor=" + encodeURIComponent(pantoneColor) +
"&photoStylingDetails=" + encodeURIComponent(photoStylingDetails) +
"&mCOMSampleId=" + mCOMSampleId +
"&deptName=" + deptName +
"&vendorName=" + encodeURIComponent(vendorName) +
"&pidStatus=" + pidStatus +
"&pidDescription=" + pidDescription +
"&webId=" + webId +
"&vStyle=" + vStyle +
"&markStyle=" + markStyle +
"&subClass=" + subClass +
"&docLineItemNum=" + docLineitemNum +
"&merchTurnInStatus=" + turnInStatus +
"&reason=" + encodeURIComponent(reason) +
"&countryOfOrigin=" + countryOfOrigin +
"&importedCountry=" + importedCountry +
"&fabricContent=" + encodeURIComponent(fabricContent) +
"&careInstructions=" + encodeURIComponent(careInstructions) +
"&offerDescription=" + encodeURIComponent(offerDescription) +
"&onlyAtMacys=" + onlyAtMacys +
"&legalOne=" + legalOne +
"&legalOneExplain=" + legalOneExplain +
"&legalTwo=" + legalTwo +
"&legalTwoExplain=" + legalTwoExplain +
"&legalThree=" + legalThree +
"&legalThreeExplain=" + legalThree +
"&legalFour=" + legalFour +
"&fifty=" + fifty +
//"&createdBy=" + userId
"&offerId=" + offerId +
"&merchId=" + merchId +
"&adID=" + adId +
"&eventID=" + eventID +
"&adNum=" + adNum
var ajaxMaster = new AjaxMaster(sql, "Puma.updateMerchFormForCutData(data)", "", "btiDispatcher.aspx");
sql = "action=updateMerchFormForCut&sql=" + encodeURIComponent(msql);
//objAjaxAd.SendQuery(sql);
// "[t0].[signedByUserID]," +
// "[t0].[signedStatus]," +
//"[t0].[dateSigned]," +
//"[t0].[signedLastByUserID]," +
//"[t0].[dateLastSigned1]," +
//"[t0].[signedLastStatus]" +
objAjaxAd.main_flag = "updateMerchFormForCutData";
objAjaxAd.SendQuery(sql);
//var ajaxMaster = new AjaxMaster(sql, "Puma.updateMerchFormForCutData(data)", "", "puma_core.aspx");
}
}
}
Write just " and not \" in the onClick attribute, or just omit the quotation marks:
onClick=Puma.saveTheCut()
The character \ has no special role in HTML; it’s just yet another character. So when you have onClick=\"Puma.saveTheCut()\", the actual attribute value is \"Puma.saveTheCut()\", which does not work of course, as you can see by looking at the console in the Developer Tools of your browser. You should see something the like following there:
SyntaxError: illegal character
\"Puma.saveTheCut()\"
(or with \"yup()\" when testing Agony’s jsfiddle).
As it is, the code should not work in any browser, and does not work in my IE 10 either.
I have a bit of Javascript that detects the browser and applies a transform to an elements depending on the browser. The one for Webkit works fine on Chrome however the Firefox one doesn't. Can someone please tell me if my code below is correct:
if(typeof navigator.vendor.toLowerCase().indexOf('chrome')!=-1){
document.getElementById('jj_preview7').style.WebkitTransform = 'scale(' + jj_input23 + ') ' + 'rotate(' + jj_input24 + 'deg)' + 'translate(' + jj_input25 + 'px, ' + jj_input26 + 'px)' + 'skew(' + jj_input27 + 'deg, ' + jj_input28 + 'deg)';
}
if(typeof navigator.vendor.toLowerCase().indexOf('firefox')!=-1){
document.getElementById('jj_preview7').style.MozTransform = 'scale(' + jj_input23 + ') ' + 'rotate(' + jj_input24 + 'deg)' + 'translate(' + jj_input25 + 'px, ' + jj_input26 + 'px)' + 'skew(' + jj_input27 + 'deg, ' + jj_input28 + 'deg)';
}
Thanks in advance
// Test element we apply both kinds of transforms to:
var testEl = document.createElement('div');
testEl.style.MozTransform = 'translate(100px) rotate(20deg)';
testEl.style.webkitTransform = 'translate(100px) rotate(20deg)';
var styleAttrLowercase = testEl.getAttribute('style').toLowerCase();
// when we check for existence of it in the style attribute;
// only valid ones will be there.
var hasMozTransform = styleAttrLowercase.indexOf('moz') !== -1;
var hasWebkitTransform = styleAttrLowercase.indexOf('webkit') !== -1;
Doing this you can now do:
var transformParts = [];
if (jj_input23 !== '') {
transformParts.push('scale(' + jj_input23 + ')');
}
if (jj_input23 !== '') {
transformParts.push('rotate(' + jj_input24 + 'deg)');
}
if (jj_input25 !== '' && jj_input26 !== '') {
transformParts.push('translate(' + jj_input25 + 'px, ' + jj_input26 + 'px)');
}
if (jj_input27 !== '' && jj_input28 !== '') {
transformParts.push('skewX(' + jj_input27 + 'deg) skewY(' + jj_input28 + 'deg)');
}
var transformTxt = transformParts.join(' ');
if (hasWebkitTransform) {
document.getElementById('jj_preview7').style.WebkitTransform = transformTxt;
}
if (hasMozTransform) {
document.getElementById('jj_preview7').style.MozTransform = transformTxt;
}
Here is the solution: http://jsfiddle.net/Adu49/1/
As you are reading from inputs directly without parse it, so you may generate CSS declaration like: scale() translate(deg,deg) which is obviously illegal. And in this case, Firefox prefer to drop it, while Chrome prefer to accept partial correct declaration. That's why your code doesn't work on Firefox but on Chrome, and after you fill all the fields it will eventually work on both browsers.
So I placed some value || default in your code, which will guaranty a proper default value is set when the input box is empty (if you want to interact with user, you need more validation code here.)
And some off-topic here. Please change the way you naming variables and elements, it's too confusing.