Jump to content
Sign in to follow this  
Carlson

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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Xiang,

 

I tried this script in the footer and it did not work. I am using a datapage update (reports details). I changed fields from InsertRecord to EditRecord and it still did not work. I tried moving script to header as well.

Share this post


Link to post
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?

Share this post


Link to post
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>

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...