Jump to content

Store A Data Field Value Based On If Or Else Conditioning


Recommended Posts

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!

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...