bookish Posted January 15, 2015 Report Share Posted January 15, 2015 Hi! May I ask how to disable a form if in the field for specifying a special diet the person places a special room request. How can the form be disabled if the person places words such as "room", "bedroom", "floor"? The error message should be "Please specify your diet requirement." Thanks in advance for your help. lbyirsva53 1 Quote Link to comment Share on other sites More sharing options...
Jan Posted January 15, 2015 Report Share Posted January 15, 2015 Hi bookish, Can you use drop-down lists instead of input fields? You can use Lookup tables with variants of special diets and special room requests. You can look for some words in the field with the following code: <SCRIPT LANGUAGE="JavaScript"> function check_text() { var text_for_checking = document.getElementById("InsertRecordtext").value; var wrong_answer = false; if (text_for_checking.search("room")!=-1) {wrong_answer = true}; if (text_for_checking.search("floor")!=-1) {wrong_answer = true}; if (wrong_answer) { alert("Please specify your diet requirement."); return false; } } document.getElementById("caspioform").onsubmit=check_text; </SCRIPT> Please, enter the name of your field instead of text in the var text_for_checking = document.getElementById("InsertRecordtext").value; You can add as many words as you wish, just copy the line if (text_for_checking.search("room")!=-1) {wrong_answer = true}; and enter your word instead of "room". To use a Java Script code, please add a Header&Footer element, select the Footer element, then click the Source button, and then enter a code. I hope it helps. bookish 1 Quote Link to comment Share on other sites More sharing options...
bookish Posted January 15, 2015 Author Report Share Posted January 15, 2015 That's brilliant, Jan. Thanks a million!!! Quote Link to comment Share on other sites More sharing options...
Jan Posted January 15, 2015 Report Share Posted January 15, 2015 You are very welcome! Quote Link to comment Share on other sites More sharing options...
bookish Posted March 8, 2015 Author Report Share Posted March 8, 2015 HI! How would I edit the code if the form is an UPDATE form? Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Jan Posted March 10, 2015 Report Share Posted March 10, 2015 Hi bookish, Please change "InsertRecord" to "EditRecord" in the line: var text_for_checking = document.getElementById("EditRecordtext").value; You can read Details in the Guide. I hope, it helps! Quote Link to comment Share on other sites More sharing options...
bookish Posted March 28, 2015 Author Report Share Posted March 28, 2015 Thank you, Jan. It's very helpful. I am sorry for late feedback. Quote Link to comment Share on other sites More sharing options...
bookish Posted March 20 Author Report Share Posted March 20 Hi! Would anyone help rewrite this script now that onsubmit will not work anymore (re disable ajax loading)? Thanks in advance! On 1/15/2015 at 4:07 PM, Jan said: Hi bookish, Can you use drop-down lists instead of input fields? You can use Lookup tables with variants of special diets and special room requests. You can look for some words in the field with the following code: <SCRIPT LANGUAGE="JavaScript"> function check_text() { var text_for_checking = document.getElementById("InsertRecordtext").value; var wrong_answer = false; if (text_for_checking.search("room")!=-1) {wrong_answer = true}; if (text_for_checking.search("floor")!=-1) {wrong_answer = true}; if (wrong_answer) { alert("Please specify your diet requirement."); return false; } } document.getElementById("caspioform").onsubmit=check_text; </SCRIPT> Please, enter the name of your field instead of text in the var text_for_checking = document.getElementById("InsertRecordtext").value; You can add as many words as you wish, just copy the line if (text_for_checking.search("room")!=-1) {wrong_answer = true}; and enter your word instead of "room". To use a Java Script code, please add a Header&Footer element, select the Footer element, then click the Source button, and then enter a code. I hope it helps. Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted March 20 Report Share Posted March 20 Hello @bookish, You can use the following code instead: <script> document.addEventListener('BeforeFormSubmit', checkValuesHandler) function checkValuesHandler(event){ const textField = document.querySelector('#InsertRecordFIELDNAME').value; //replace FIELDNAME with your field name if(textField.includes('room') || textField.includes('floor') || textField.includes('bedroom')){ event.preventDefault(); alert('Please specify your diet requirement.'); } } </script> You can add more conditions if needed. Just copy this part and replace the keyword. || textField.includes('KEYWORD') You may use an additional tool for displaying pop-up messages instead of the basic browser alert. For that, you can use the following code: <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script> document.addEventListener('BeforeFormSubmit', checkValuesHandler) function checkValuesHandler(event){ const textField = document.querySelector('#InsertRecordFIELDNAME').value; //replace FIELDNAME with your field name if(textField.includes('room') || textField.includes('floor') || textField.includes('bedroom')){ event.preventDefault(); Swal.fire( '', 'Please specify your diet requirement.', 'warning' ); } } </script> This is an example: bookish 1 Quote Link to comment Share on other sites More sharing options...
bookish Posted March 21 Author Report Share Posted March 21 Thank you so much @CoopperBackpack! I will try it soon (this weekend) and I will let you know how it works for my programs! CoopperBackpack 1 Quote Link to comment Share on other sites More sharing options...
bookish Posted March 23 Author Report Share Posted March 23 HI @CoopperBackpack, I used your second script (pop-up message instead of browser alert). It worked! I just had to put the code because if the one booking typically uses CAPS then the form will submit. const nonDietRegex = /room|floor|bedroom/i; if(nonDietRegex.test(textField)) { CoopperBackpack 1 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.