vdb@telenet.be Posted August 28, 2014 Report Share Posted August 28, 2014 For example a 'check' field... ik cannot do [@example]=[@example]+1 when checked Someone can help me out? thanx Bart Quote Link to comment Share on other sites More sharing options...
vdb@telenet.be Posted August 28, 2014 Author Report Share Posted August 28, 2014 I found already this, but it concatenate instead of addition... Can anybody make this script work? <SCRIPT LANGUAGE="JavaScript"> function add() { var position1 =document.getElementById("EditRecordR397_Gegrilde_eend_sappig").value; var position2 = 1 var allpositions = position1 + position2; document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value =allpositions; } document.getElementById("caspioform").onsubmit=add; </SCRIPT>> Quote Link to comment Share on other sites More sharing options...
vdb@telenet.be Posted August 28, 2014 Author Report Share Posted August 28, 2014 I can add numbers now, but i can not do the 'if then' check.. When Virtual1 is "Y" then add +1 to Fieldxx Thank you if you could help me out.. Bart <SCRIPT LANGUAGE="JavaScript"> function add() { var totalVal = parseInt((document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value)) + (+1) document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value =totalVal; } if (document.getElementById("@cbParamVirtual1").value == "Y") { document.getElementById("caspioform").onsubmit=add; } </SCRIPT>> Quote Link to comment Share on other sites More sharing options...
GoCubbies Posted August 28, 2014 Report Share Posted August 28, 2014 Check the line var totalVal = parseInt((document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value)) + (+1) as it is missing a ";". Also if (document.getElementById("@cbParamVirtual1").value == "Y"), remove the "@". Have you tried the following: var is_checked = document.getElementByID("cbParamVirtual1").checked; if(is_checked){ document.getElementById("caspioform").onsubmit=add; } Quote Link to comment Share on other sites More sharing options...
vdb@telenet.be Posted August 28, 2014 Author Report Share Posted August 28, 2014 hi GoCubbies, thank you for the advice. I tested all, but still not add +1 when the checkbox is checked. The code for adding +1 to another field is working, but it is like the if-then code is not detecting anything? I am searching this for 2 days already. Maybe you can see other faults? thanx, Bart Belgium the updated code: <SCRIPT LANGUAGE="JavaScript"> function add() { var totalVal = parseInt((document.getElementById ("EditRecordR393_Kip_met_Marrokaanse_kruiden").value;)) + (+1) document.getElementById ("EditRecordR393_Kip_met_Marrokaanse_kruiden").value; =totalVal; } function is_checked_and_change() { var is_checked = document.getElementById("cbParamVirtual1").checked; if (is_checked) { document.getElementById("caspioform").onsubmit=add; } } </SCRIPT>> Quote Link to comment Share on other sites More sharing options...
Jan Posted September 1, 2014 Report Share Posted September 1, 2014 Hello Mel, If I understand correctly, you can use the following code: <SCRIPT LANGUAGE="JavaScript"> function add() { var is_checked = document.getElementById("cbParamVirtual1").checked; if (is_checked) { var totalVal = parseInt(document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value); totalVal = totalVal + 1; document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value=totalVal; } } document.getElementById("caspioform").onsubmit=add; </SCRIPT> And it requires set the field R393_Kip_met_Marrokaanse_kruiden as Hidden, select Data Source Fields in the On load assign drop down box, and selet your field in the next drop down box. I hope, it helps. Quote Link to comment Share on other sites More sharing options...
vdb@telenet.be Posted September 2, 2014 Author Report Share Posted September 2, 2014 I tested this with checkbox and radiobuttons, did not work. Only List and dropdown give the info... Finaly i worked with this to add up 1 to the existing amount: <script language="JavaScript">function concatenate(){var position1 = parseInt(document.getElementById("cbParamVirtual1").value);var position2 = parseInt(document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value);var allpositions = position1 + position2;document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value=allpositions;}document.getElementById("caspioform").onsubmit=concatenate;</SCRIPT> many thanx! Mel Quote Link to comment Share on other sites More sharing options...
GoCubbies Posted September 2, 2014 Report Share Posted September 2, 2014 Mel, In terms of the code Jan provided, my understanding is that the virtual field as a checkbox did not function. Are there other virtual fields present on the page, or is this checkbox the only one. The reason I ask is that the naming of the form element of virtual fields may be the issue. As a reference, take a look at http://forums.caspio.com/index.php/topic/4377-js-guide-caspio-form-elements/. I was able to test out Jan's code both with a virtual checkbox field and a YES/NO datatype field from table and it worked in a test page that I created. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.