Jump to content
  • 0

CSS If Statement


RonAnderson
 Share

Question

Hi,

I have a field [Value] in my submission datapage which will contain either "Yes" of "No". If [Value] = "Yes" then I want another field [Count] to be read only. If [Value] = "No" then I want the [Count] field to be editable.

I found this code which works perfectly but I need it to handle both conditions

<style>
input[name*="Count"]
{
pointer-events: none !important;
}
</style>

I'm a total novice with CSS syntax so I'd be grateful for any help with this.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 1

Hi @RonAnderson! I can totally relate because I'm not that familiar with CSS as well :D Have you tried using Rules instead? It can hide,  disable, required, and make a field/section as read-only based on conditions. 

https://howto.caspio.com/datapages/forms/conditional-forms/

This is a much easier approach instead of css. I hope this helps!

Link to comment
Share on other sites

  • 0

Hi @ParkLoey and thanks for responding so quickly. I tried using rules but because the Count field has been used in another rule it fails to appear in the "Select Field". I don't want to go down the path of restructuring the  rules because they took ages to build and I don't want to unravel them. I may have to do this if I can't get a code solution.

Link to comment
Share on other sites

  • 0

You can also use JavaScript to disable a field:

<script type="text/javascript">
var field = document.getElementsByName('InsertRecordField')[0];
field.addEventListener('change', function() {

if(field.value == "Yes"){
document.querySelector("[id*='InsertRecordCount']").readOnly = true;
}
else{
document.querySelector("[id*='InsertRecordCount']").disabled = false;
}
});
</script>

Please note to change Field and Count in the InsertRecordField and InsertRecordCount according to your correct field names.

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
Answer this question...

×   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...