ChrisCarlson Posted June 15, 2015 Report Share Posted June 15, 2015 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? Quote Link to comment Share on other sites More sharing options...
LWSChad Posted June 18, 2015 Report Share Posted June 18, 2015 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 Quote Link to comment Share on other sites More sharing options...
Jan Posted June 19, 2015 Report Share Posted June 19, 2015 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> Quote Link to comment Share on other sites More sharing options...
ChrisCarlson Posted June 20, 2015 Author Report Share Posted June 20, 2015 Jan, thanks this will work for the issue! Quote Link to comment Share on other sites More sharing options...
alexm72 Posted August 17, 2017 Report Share Posted August 17, 2017 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? Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted August 17, 2017 Report Share Posted August 17, 2017 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. Quote Link to comment Share on other sites More sharing options...
alexm72 Posted August 17, 2017 Report Share Posted August 17, 2017 (edited) I tried it and it didnt work. I changed the value to [@authfield:Username]. I also tried it with "Bad Name". They should really make this more easy. Logiforms has a hide Submit feature Edited August 20, 2017 by alexm72 tried it out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.