charlene Posted February 17, 2014 Report Share Posted February 17, 2014 Hi, How could I create a script code to store a data field value based on the if or else conditions? What I am trying to achieve is that If both field 1 and field 2 equal "Yes", then store a value of "Eligible" in field 3 Else store a value of "InEligible" in field 3. Please help. Thank you! Quote Link to comment Share on other sites More sharing options...
Jan Posted February 19, 2014 Report Share Posted February 19, 2014 Hello Charlene, You can try the code like this: <SCRIPT LANGUAGE="JavaScript"> function myFunction() { var virtual1 = document.getElementById("InsertRecordfield1").checked; var virtual2 = document.getElementById("InsertRecordfield2").checked; if (virtual1) { if (virtual2) { document.getElementById("InsertRecordfield3").value = "Eligible"; } else { document.getElementById("InsertRecordfield3").value = "InEligible"; } } else { document.getElementById("InsertRecordfield3").value = "InEligible"; } } document.getElementById("caspioform").onsubmit=myFunction; </SCRIPT> Add the code to the Footer of your DataPage. Quote Link to comment Share on other sites More sharing options...
charlene Posted February 19, 2014 Author Report Share Posted February 19, 2014 Thanks Jan. I had the code below, but it doesn't seem to work. Could you please help me take a look at it? My form is an update form. <SCRIPT LANGUAGE="JavaScript"> function myFunction() { var virtual1 = document.getElementById("EditRecordV1_ExemptTruck").value; var virtual2 = document.getElementById("EditRecordV1_OnRoadClass8").value; if (virtual1=='Yes') { if (virtual2=='Yes') { document.getElementById("EditRecordfield3").value = "Eligible"; } else { document.getElementById("EditRecordfield3").value = "InEligible"; } } else { document.getElementById("EditRecordfield3").value = "InEligible"; } } document.getElementById("caspioform").onsubmit=myFunction; </SCRIPT> Do I need to change the name of my form to be "caspio form" to match the last command? Quote Link to comment Share on other sites More sharing options...
Jan Posted February 20, 2014 Report Share Posted February 20, 2014 Hello Charlene, No, you don't need to change the name of your form. If "V1_ExemptTruck" and "V1_OnRoadClass8" are virtual fields, then the code should be like var virtual1 = document.getElementById("cbParamV1_ExemptTruck").value; var virtual2 = document.getElementById("cbParamV1_OnRoadClass8").value; Quote Link to comment Share on other sites More sharing options...
luizcruz Posted February 21, 2014 Report Share Posted February 21, 2014 Thanks Jan. I had the code below, but it doesn't seem to work. Could you please help me take a look at it? My form is an update form. <SCRIPT LANGUAGE="JavaScript"> function myFunction() { var virtual1 = document.getElementById("EditRecordV1_ExemptTruck").value; var virtual2 = document.getElementById("EditRecordV1_OnRoadClass8").value; if (virtual1=='Yes') { if (virtual2=='Yes') { document.getElementById("EditRecordfield3").value = "Eligible"; } else { document.getElementById("EditRecordfield3").value = "InEligible"; } } else { document.getElementById("EditRecordfield3").value = "InEligible"; } } document.getElementById("caspioform").onsubmit=myFunction; </SCRIPT> Do I need to change the name of my form to be "caspio form" to match the last command? Hi Charlene! Please, What type are your fields? Dropdown, Checkbox? Luiz Quote Link to comment Share on other sites More sharing options...
Barbara Posted March 4, 2014 Report Share Posted March 4, 2014 Charlene, were you able to get it to work yet? One other note is that if your fields are editable you can refer to them as EditRecordFieldName, if your fields are Display Only then there is no ID to refer to and that could be a reason your script is not working. 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.