Jump to content

On Submit Check For File Fields If Blank


Recommended Posts

I am looking for a way to check if file attachment fields are blank at time of submit. I have 8 file attachment fields and I want to display a message if any of the 8 are blank. Allow the user to confirm (OK - proceed with submit) or cancel (Cancel - allow user to complete fields prior to submit). I would normally user required field setting however the fields are optional and the message would be FYI only. This also becomes an issue when page reloads and drops the file attachments where remaining fields are intact, and user does not notice attachment fields are blank on final submit.

Link to comment
Share on other sites

Hi ccarls3,

 

How are you doing?

 

I've wrote a simple script: if an image field is empty, the error message is displayed. When a user clicks the second time, the record is added.

You can add as many fields as you want.

<SCRIPT LANGUAGE="JavaScript">
var first_time = true;
function check_images()
{
var image1 = document.getElementById("InsertRecordfile1").value;
var image2 = document.getElementById("InsertRecordfile2").value;
var image3 = document.getElementById("InsertRecordfile3").value;
var emptyFields = false;
if (image1.length < 1) emptyFields = true;
if (image2.length < 1) emptyFields = true;
if (image3.length < 1) emptyFields = true;
if ( emptyFields)
  {
   if (first_time)
    {
      first_time = false;
      alert("Image field is empty. If you want to continue, please click Submit again");
      return false;
     }
  }
}
document.getElementById("caspioform").onsubmit=check_images;
</SCRIPT>

If you want a pop-up window, I'll try writing a new code :)

 

Have a nice day!

Link to comment
Share on other sites

It's interesting! :)

I just check on the Details page, code works.

Could you verify:

"file1", "file2", "file3" are changed to the names of your fields;

These fields are editable;

the code is entered to the Footer of the DataPage (not the webpage) and the "Source" button is clicked.

 

Could you send a URL?

Link to comment
Share on other sites

I placed the following script in my footer but it does not work, This is on an update datapage. Is the onsubmit correct?

 

<SCRIPT LANGUAGE="JavaScript">
var first_time = true;
function check_images()
{
var image1 = document.getElementById("EditRecordPhoto_Attachment1_File").value;
var image2 = document.getElementById("EditRecordPhoto_Attachment2_File").value;
var image3 = document.getElementById("EditRecordPhoto_Attachment3_File").value;
var emptyFields = false;
if (image1.length < 1) emptyFields = true;
if (image2.length < 1) emptyFields = true;
if (image3.length < 1) emptyFields = true;
if ( emptyFields)
  {
   if (first_time)
    {
      first_time = false;
      alert("Image field is empty. If you want to continue, please click Submit again");
      return false;
     }
  }
}
document.getElementById("caspioform").onsubmit=check_images;
</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
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...