Jump to content
  • 0

Check multiple criteria in js before activating Submit on a custom button


DesiLogi

Question

Hello,

I need to use a custom Update/Submit button (on a Details form) because I need to use rules to show/hide some required fields. If the fields are set to 'Required' they cannot be hidden using Rules. So I unchecked the 'Required' box for those fields. I am using a custom Update button (hiding in Styles the default one) so I can put checking code in before the record is Updated, to make sure those fields aren't null. 

I don't know exactly how to code this because the button type needs to be "button" (instead of "submit") so it will run the checking code. If neither of the fields are null then I need the button to run "submit" code. If either of the fields are blank I need an alert box to show and no "submit" code to run. 

1) does anyone know how to put in an 'else' statement that changes the button type to "submit" so if fieldA and fieldB are not null it submits?

2) does anyone know how to put an 'if both FieldA AND FieldB are NOT null then "submit"? I need it to only submit if both fieldA AND fieldB are not null. I'm not sure of the syntax for that. 

Here's the code I'm using so far- thanks for any help.

<div style="text-align: center;">
<input class= "cb_custom_btn" type="button" onclick="myFunction()" value="Check Required & Update" />

<script>
function myFunction(){ 
var v_fielda = document.getElementById("EditRecordFieldA").value;
if(!isNaN(v_fielda))
{

alert("Field A is required");
}
var v_fieldb = document.getElementById("EditRecordFieldB").value;
if(!isNaN(v_fieldb))
{

alert("Field B is required");
}
--// here I need something that does "if both fieldA AND fieldB = not null then run "submit" (but do NOT run "submit" if either FieldA OR FieldB = null) //--
}
</script>
</div>

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

If anyone needs the solution to this I worked it out with Caspio's help. Here it is: 

 

<div style="text-align: center;">
<input class= "cb_custom_btn" type="Submit" onclick="return myFunction()" value="Check Required & Update" />
</div>
<script>
function myFunction(){
var v_fielda = document.getElementById("EditRecordA").value;
var v_fieldb = document.getElementById("EditRecordB").value;
if(!isNaN(v_fielda))
 
{
alert("Field A is required");
return false;
 
}
 
else if(!isNaN(v_fieldb))
{
alert("Field B is required");
return false;
}
else{
return true;
}
 
}
</script>

 

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