2017-01-06 60 views
-2
<form action="<?php echo base_url();?>test/loadsql" method="post" enctype="multipart/form-data"> 
        <input type="file" required aria-required="true" id="upload" name="upload"/> 
        <input type="button" onclick="validate()" class="btn btn-success " value= "Upload"> 
        </form> 

function validate() 
{ 
    job=confirm("Are you sure to upload?"); 
    if(job!=true) 
    { 
     return false; 
    } 
} 
</script> 

如果真的,我要加載的形式作用的測試/ loadsql用JavaScript笨彈出驗證

請幫助

回答

0

更改按鈕類型submit而不是button並聲明點擊功能return是非常重要的返回功能

已更新的答案驗證輸入

function validate() 
 
{ 
 
    var input =document.getElementById('upload').value; 
 
    if(input){ 
 
     var job=confirm("Are you sure to upload?"); 
 
    if(job!=true) 
 
    { 
 
     console.log('not allow') 
 
     return false; 
 
    } 
 
    else{ 
 
    console.log("pass") 
 
     return true; 
 
    } 
 
    } 
 
    else{ 
 
    alert('Please choose some file') 
 
    } 
 
}
<form action="<?php echo base_url();?>test/loadsql" method="post" enctype="multipart/form-data"> 
 
        <input type="file" required aria-required="true" id="upload" name="upload"/> 
 
        <input type="submit" onclick="return validate()" class="btn btn-success " value= "Upload"> 
 
        </form>

+0

喜ALL,正如我已經給 gosatriani

+0

你能告訴你是否需要兩次確認嗎? – prasanth

+0

首先,當我點擊上傳時,它應該提醒(「沒有選擇文件」)。一旦文件上傳,然後點擊上傳,它應該要求的消息「你確定要上傳」謝謝 – gosatriani

0

使用onsubmit()事件上如下形式..

檢視:

<form action="<?php echo base_url('test/loadsql');?>" method="post" enctype="multipart/form-data" onsubmit="validate();"> 

<input type="file" required aria-required="true" id="upload" name="upload"/> 
<input type="submit" class="btn btn-success" value= "Upload"> 

</form> 

的Javascript

function validate() 
{ 
    if(window.confirm("Are you sure to upload?")) 
    { 
     return true; 
    } 
    else{ 
     return false; 
    } 
}