Jump to content
  • 0

Disable Submit Button Based On 2 Values Being Different


zalipresents

Question

I'm using a details page to update a record in my table & on the details page are a variety of calculations that i've written to calculate "onchange" on the page.  Things are working properly, however now i'd like to disable the sumbit button if "Field_A" & "Field_B" do not match.  To add a layer to this, i'd like to know how to use an HTML block as one of these fields since it's where the calculation happens and i'd also like to know if i can have multiple criteria that disable the submit button.  I'm thinking that I need to assign a field name to the HTML block, however I don't know how to do that unfortunately.  How would the code for this situation be written?

 

"Field_A" value must equal "HTML block 22" in order for the submit button to be enabled

 

OR

 

"Field_A" value must equal "HTML block 22" AND "Field_B" value must equal "Field_C" for the submit button to be enabled

 

I saw a topic on this question if a value is greater than 0, however nothing on how to change the 0 to a comparison between 2 fields.

 

Thanks!

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hello zalipresents! 

 

I am afraid you can not use HTML block as a field because you can not take its values.

 

However, you can use the following script if you like to disable Submit button if Field A is not equal Field B : 

<SCRIPT LANGUAGE="JavaScript">

 function myFunction()
{
   var field_a = document.getElementById("EditRecordField_A").value;
   var field_b = document.getElementById("EditRecordField_B").value;

  if (field_a !== field_{

     alert("Field A is not equal Field B");
     return false;                     } 
   
}


document.getElementById("caspioform").onsubmit = myFunction; 

 I hope this information helps 

 

Aurora

Link to comment
Share on other sites

  • 0

Awesome, this will help a ton.  what if i wanted to recreate the formula that the HTML block is doing, how would I enter that?  Here is a summary example:

 

Field_A 

value 50

 

Field_B

value 50

 

Field_C

value 100

 

submit requirement:

 

need Field_A + Field_B to equal Field_C in order for the button to be enabled

 

make sense?  I'm just trying to see if a formula can be used in the javascript since an HTML block can't be...another option is I can have a duplicate field and tell the HTML block to display the result in that as well as the HTML block, however i'd rather not add anymore fields to my table unless 100% necessary.  Also i'll put all this in the footer right?

 

Thanks!

Link to comment
Share on other sites

  • 0

Yes, you will put the script  into the Footer. Please make sure that the button " Source" is selected!

 

If i understand you correctly, you want to store formula's result in the HTML block ? If yes, then  Formula can't be used in JS as well , because JS works with fields IDs, and HTML block does't store the result, it just displays it. If you have a formula and store it in a separate hidden field (say Field D ), we can use then a value of a Calculated Field and use it in JS.

 

Let me know if this option is ok for you, I will help you with the script.

 

 

Aurora

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...
×
×
  • Create New...