Jump to content

Disable Submit Button Based On Field Value


Recommended Posts

I have a submission form with 12 numeric fields where the user is required to enter as positive amounts. I would like to disable the submit button when this condition exists. In some cases the 12 fields may not have data entered, so I need to check either if positive or if blank then allow submit. Can this be achieved via javascript? 

Link to comment
Share on other sites

Text field IDs are

EditRecord[fieldSource]
or
InserRecord[fieldSource]

Submit button IDs are

Submit

something like

var field1 = document.getElementById('EditRecord[fieldSource]');
var submitBtn = document.getElementById('Submit');

if (field1.value != Null){
 if (field1.value > 0) {
  submitBtn.style.display = 'block';
 }
}

If you have to test multiple fields add layers of "if"s

(Or use a loop... that would the right way to do it, but IDK js loops)

 

Hope this helps

Link to comment
Share on other sites

Hello ccarls3,

 

I have written the following script. It does not disable the "Submit" button, but when a user clicks "Submit", the script checks, if any negative number is entered. If yes, the error message is displayed and the record is not added.

<script language="JavaScript">
function check_numbers()
{
var disabled = false;
if (parseFloat(document.getElementById("InsertRecordfield1").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield2").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield3").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield4").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield5").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield6").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield7").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield8").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield9").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield10").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield11").value)<0) disabled = true;
if (parseFloat(document.getElementById("InsertRecordfield12").value)<0) disabled = true;

if (disabled)
{
alert("Negative values are not allowed");
return false;
}
}
document.getElementById("caspioform").onsubmit=check_numbers;
</script>
Link to comment
Share on other sites

  • 2 years later...

How do i write the code if the field is a name that I don't want submitted?  Where do I put the script..(im not good at JS).  I tried something like this

if (parseFloat(document.getElementById("InsertRecordMyTestField").value)="BadName") disabled = true;
do I use quotes for the text i want to restrict or apostrophes?
Link to comment
Share on other sites

5 hours ago, alexm72 said:

How do i write the code if the field is a name that I don't want submitted?  Where do I put the script..(im not good at JS).  I tried something like this


if (parseFloat(document.getElementById("InsertRecordMyTestField").value)="BadName") disabled = true;

do I use quotes for the text i want to restrict or apostrophes?

Hi Alexm72,

You should put Javascript code into the Footer element of Datapage. Please make sure that you disable HTML editor before inserting the code.

I have created following JS for your particular case. Please note that this JS designed for Submission Form Datapage.

<script language="JavaScript">
function check_string ()
{
var disabled = false;
if (document.getElementById("InsertRecordMyTestField").value) == BadName”) disabled = true;
if (disabled)
{
alert("Bad Name are not allowed");
return false;
}
}
document.getElementById("caspioform").onsubmit=check_string;
</script>

 

Hope this helps.

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