Jquery return false not stopping form submit

My purpose is to stop submitting form if no attachment is attached.

$(document).ready ( function () {
   $('button[type="submit"]').on('click', function(e){
   		if ($('input[name="attach_document"]')[0].value == "" ) {
   			e.preventDefault();
   			alert("No File Attached");
   			return false;
   		}
   });
});

Please help me to find why the code doesnot work. Thanks

@vivin_joseph use

frappe.throw(__("Please select Company"));

@khushal_t Thanks…
Its not working.its showing frappe.throw is not a function

@vivin_joseph on which form ?

@khushal_t webform

@vivin_joseph It works within desk since it is webform you yourself need to write binding events so your code with
return false; is right you check with browser debugger where you can see each line execution you may trace something that you are missing

Try putting e.preventDefault();

@netchampfaris I have used it.

Do your alert box promting??

Sorry, missed it.

Don’t bind the event on button click, bind it when form is submitted

$('form').on('submit', function() {
    if ($('input[name="attach_document"]')[0].value == "" ) {
   		e.preventDefault();
   		alert("No File Attached");
   		return false;
   	}
})

@khushal_t alert box is showing and form submits

@netchampfaris the form again submits

can you show your all code ??