Validate form when press "buy it now" button

Hello,

On product page, I have “upload file” field and “note” field (It’s custom field.), They are required field.
I use getElementsByClassName(“shopify-payment-button__button”) and add onclick by javascript

for validate 2 fields (“upload file” field and “note” field).

I use preventDefault() and stopImmediatePropagation()
It is not work, I cannot stop for go to checkout page.

What do I do validate “upload file” field and “note” field before before “buy it now” button works ?

Hi,

  1. For file input create,

  1. Inside script tag create function
function ValidateFileInput() {
            var fileInput = document.getElementById('file');

along with this you need to check file(allowed extensions like .jpg, .jepg, .png, etc)
3.

<input type="text" name="firstname" id="firstname" />

Check validation for,

var fname = document.getElementById('firstname');
if (fileInput.file && fname) {
// Your code goes here
   } // clsoe if statement
}  // function
  1. Buy Now button

onclick=“return ValidateFileInput()”

I cannot validate for “buy it now” button.

before when I upload file, I hide “buy it now” button
After upload success, I show “buy it now” button

where to paste this code . i tried to pace this code in poduct.liquid buy it is not working pls help to slove this . for my custom field i need to validate for buy it now button