2010-11-18 91 views
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> 

在我的jsp文件中,我有上面的代碼。如果沒有選擇文件,alert('Please upload a file')顯示成功。但它調用了Servlet程序Readcsvv並進入下一頁。使用jsp調用javascript函數時出現問題

浸完警報框後,我想要編程在同一頁面中。我該怎麼做?

+0

[汽車/地毯(http://stackoverflow.com/questions/245062/javascript-and-java/245068#245068)你知道嗎... – aioobe 2010-11-18 08:33:35

回答

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="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> 
+0

非常感謝Ramesh :) – Anand 2010-11-18 08:46:14

0

如果這是jQuery,您必須在onClick事件處理程序結束時返回false。我會嘗試return false;

您還需要將onclick屬性更改爲form元素上的onsubmit屬性。

+0

I在if條件中嘗試了'return false;'。它不工作,雖然.. – Anand 2010-11-18 08:34:47

+0

所以你看到警報,但一旦你解僱它,頁面仍然改變? – 2010-11-18 08:37:09

+0

是的絕對.. – Anand 2010-11-18 08:42:23

1

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

使用這種帶有返回false

+0

即使我已經試過這個......它不工作:( – Anand 2010-11-18 08:36:20

0

試試這個:

<form name='frm' action="Readcsvv" enctype="multipart/form-data" method="POST" onSubmit="return false;"> 
相關問題