-4

I have created a form in html. I have added event listener on file browsing field and also there is some condition to be checked before submitting the form. So i have used

onsubmit="return myfunction()"

If myfunction is returning false, an alert window pops. On clicking on the 'ok' of alert window the form is getting submitted.

Also the onsubmit action is not working everytime. It works just once. So next time if I entry invalid details in form and click Submit the form is submitted. Is there anything that I am missing ?

masud_moni
  • 1,121
  • 16
  • 33
Snehal
  • 1
  • 1
  • 3
  • 2
    please include your code – Abdul Rafay Feb 28 '17 at 11:03
  • 1
    You should post your relevant code; otherwise we don't have any idea what is going wrong. Also please see http://stackoverflow.com/help/how-to-ask – bj7 Feb 28 '17 at 11:04
  • 1
    Welcome to [Stack Overflow](http://stackoverflow.com/) ! Please read [How to Ask Question](http://stackoverflow.com/help/how-to-ask) and provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) ! – Saurabh Bhandari Feb 28 '17 at 11:05
  • 2
    Edit your title to be **more specific** please. – Mistalis Feb 28 '17 at 11:05
  • @AbdulRafay
    Email Address* :
    Project Name*:
    Upload fasta file:

    – Snehal Feb 28 '17 at 11:11
  • "Is there anything that I am missing" - nope I think you've covered everything. Good luck – Jaromanda X Feb 28 '17 at 11:13
  • @AbdulRafay – Snehal Feb 28 '17 at 11:16
  • @AbdulRafayfunction checkfiles() { var fup=document.getElementById('l1'); var t = fup.innerText; if(t=='Not a fasta format') { //alert("Upload fasta format file"); fup.innerText="Please upload a fasta format file"; //out.println("upload .fa file"); fup.focus(); return false; } else { return true; } } – Snehal Feb 28 '17 at 11:17
  • 1
    You can edit your question, please do that instead of posting them as comments. Also post them as a snippet if possible. (To make a snippet click the last button in the second column and make sure it works by hitting run) – A. L Feb 28 '17 at 11:47

1 Answers1

0

On checking the structure of the code ! it seems you are checking the file format only during window.onload() which would be set to Not a fasta format because its null as no object is loaded at start, so try to include it in the function call checkfiles() and it should work! I guess you are trying to check the format when the user loads the file then please check the below thread check onload for input elements

Community
  • 1
  • 1
Suhaas
  • 11
  • 2