使用javascript进行必需的Fileupload验证 [英] Required Fileupload validation using javascript

查看:61
本文介绍了使用javascript进行必需的Fileupload验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我有一个带控件的网页。这是一个注册表。



在这里,我想用javascript验证上传控件。



我想要只上传除这些之外的PDF文件。



这是我的Javascript代码。



< pre lang =xml> < script 类型 = text / javascript >
函数Validate(){
var txt1 = document.getElementById('TxtName');
var txt2 = document.getElementById('DDLReason');
var txt3 = document.getElementById('DDLCondition');
var uploadfile = document.getElementById('FileUploadTurnInRequest');

if(txt1.value =='')
{
alert('Please enter Name');
返回false;
}

if(uploadfile.value =='')
{
alert('请上传附件');
返回false;
}


if(document.getElementById('<% = DDLReason.ClientID %> ')。selectedIndex == 0)
{
alert(请选择原因);
返回false;
}

if(document.getElementById('<% = DDLcondition.ClientID %> ')。selectedIndex == 0)
{
alert(请选择条件);
返回false;
}
其他
{
返回确认('你确定,你要提交?')
}
}
< / script >







按钮

------

< asp:ImageButton ID =   btnUpdate runat =   server CausesValidation =   true 
ImageUrl = 〜/ User / Images / Submit1 .png宽度= 180px
高度= 40px OnClientClick = javascript:return Validate()
onclick = btnUpdate_Click />









在这里,我需要使用Javascript进行验证,仅用于上传PDF文件。



请帮助

解决方案

功能验证(thisform)
{
with(thisform )
{
if (validateFileExtension(file, valid_msg 仅允许使用pdf文件!
new 数组( pdf))== false
{
return false ;
}
if (validateFileSize(file, 1048576 valid_msg 文件大小应小于1MB!)== false
{
返回 false ;
}
}
}



how-to-validate-upload-file-size-and-file-extension-using-javascript / [ ^ ]

how-do-i-validate-the-file-type-of-file-upload [ ^ ]

<试试这个: -



  var  uploadfile = document.getElementById('  FileUploadTurnInRequest'); 

if (uploadfile。 value .match(/ pdf


/)|| uploadfile。 value .match(/ PDF


Hi Friends,

I have a webpage with controls in it. This is a registration form.

Here, i want to validate Upload control using javascript.

I want to upload only PDF Files not other than these.

This is my Javascript code.

<script type="text/javascript">
        function Validate() {
            var txt1 = document.getElementById('TxtName');
            var txt2 = document.getElementById('DDLReason');
            var txt3 = document.getElementById('DDLCondition');
            var uploadfile = document.getElementById('FileUploadTurnInRequest');

            if(txt1.value == '')
            {
                alert('Please enter Name');
                return false;
            }

             if(uploadfile.value == '')
            {
                alert('Please upload the attachment');
                return false;
            }


if(document.getElementById('<%=DDLReason.ClientID%>').selectedIndex == 0)
{
alert("Please Select Reason");
return false;
}

if(document.getElementById('<%=DDLcondition.ClientID%>').selectedIndex == 0)
{
alert("Please Select Condition");
return false;
}
 else
  {
  return confirm('Are you Sure, you want to Submit ?')
  }
    }
    </script>




Button
------

<asp:ImageButton ID="btnUpdate" runat="server" CausesValidation="true"
                                                                   ImageUrl="~/User/Images/Submit1.png" Width="180px" 
                                                                    Height="40px" OnClientClick="javascript:return Validate()"
                                                                   onclick="btnUpdate_Click"/>





Here, Just i need Validation using Javascript, Only to Upload PDF Files.

Please help

解决方案

function validation(thisform)
{
   with(thisform)
   {
      if(validateFileExtension(file, "valid_msg", "pdf files are only allowed!",
      new Array("pdf")) == false)
      {
         return false;
      }
      if(validateFileSize(file,1048576, "valid_msg", "Document size should be less than 1MB !")==false)
      {
         return false;
      }
   }
}


how-to-validate-upload-file-size-and-file-extension-using-javascript/[^]
how-do-i-validate-the-file-type-of-a-file-upload[^]


try this:-

var uploadfile = document.getElementById('FileUploadTurnInRequest');

if (uploadfile .value.match(/pdf


/) || uploadfile .value.match(/PDF


这篇关于使用javascript进行必需的Fileupload验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆