0
<form name='frm' action="Readcsvv" enctype="multipart/form-data" method="POST" > 
<input type="file" name="file1"><br><br>
<input type="Submit" value="Upload File" onclick="showProgress()" method="POST">

<script>
function showProgress() {
    if(document.frm.file1.value == "")
    {
    alert('Please upload a file');
    }       
    else
    {       
    document.getElementById('progress').style.display = 'block';
    }
    }
</script>

In my jsp file I have the above code. If there is no file selected the alert('Please upload a file') is displayed successfully . But it calls the servlet program Readcsvv and goes to the next page.

After diplaying the alert box i want to program to be in same page. What should I do for that?

Peter
  • 5,728
  • 20
  • 23
Anand
  • 17
  • 1
  • 8
  • [Car / Carpet](http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java/245068#245068) you know... – aioobe Nov 18 '10 at 08:33

4 Answers4

1

<input type="Submit" value="Upload File" onclick="return showProgress()" method="POST">

use this with return false

Eric
  • 1,171
  • 2
  • 14
  • 27
0

If this were jQuery you would have to return false at the end of an onClick event handler. I would try return false;.

You also need to change your onclick attribute to be an onsubmit attribute on the form element.

Marcus Whybrow
  • 19,578
  • 9
  • 70
  • 90
0

Try this:

<form name='frm' action="Readcsvv" enctype="multipart/form-data" method="POST" onSubmit="return false;"> 
Asif Mulla
  • 1,652
  • 2
  • 22
  • 32
0

Try below,

<form name='frm' action="Readcsvv" enctype="multipart/form-data" method="POST" > 
<input type="file" name="file1"><br><br>
<input type="Submit" value="Upload File" onclick="return showProgress();" method="POST">

<script>
function showProgress() {
    if(document.frm.file1.value == "")
    {
    alert('Please upload a file');
    return false;
    }       
    else
    {       
    document.getElementById('progress').style.display = 'block';
    return true;
    }
    }
</script>
Ramesh
  • 13,043
  • 3
  • 52
  • 88