使用java脚本在asp.net中验证文本框和下拉列表 [英] Validate textbox and dropdownlist in asp.net using java script

查看:79
本文介绍了使用java脚本在asp.net中验证文本框和下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    var Pname = document.getElementById('<%=txtdate.ClientID %>').value;
            if (Pname == " " ) {
                alert("Please Enter Date.");
                return false;
            }
  var vechileno = document.getElementById('<%=txtVehicleNo.ClientID %>').value;
            if (vechileno == " " ) {
                alert("Please Enter  Vehicle Number.");
                return false;
            }

           var ddlItemtype = document.getElementById('<%=ddlItemtype.ClientID%>');
            var ddlitem = ddlItemtype.options[ddlItemtype.selectedIndex].value;
            if (ddlitem == 0) {
                alert("Please Select Item.");
                return false;
            }
            var ddltrader = document.getElementById('<%=ddltradername.ClientID%>');
            var ddlproductype1 = ddltrader.options[ddltrader.selectedIndex].value;
            if (ddlproductype1 == 0) {
                alert(" Please Select Trader Name.");
                return false;
            }
}





点击按钮我在javascript中调用此函数

我有很多文本框和下拉列表。我想用于每个循环并显示错误。



我一直在编写这样的代码。并且编码的长度增加。是否有任何优化方法来减少代码。



On button click I am calling this function in javascript
I have manytextboxes and dropdown list like this . I want to use for each loop and display the error.

I am writing the code all the time like this. And the length of coding increasing. Is there any optimize way to reduce the code.

推荐答案

自定义下面的提示/技巧



< a href =http://www.codeproject.com/Tips/61792/Simple-and-easy-way-to-clear-all-the-input-fields>清除所有输入字段的简单方法表格。 [ ^ ]
Customize the below Tip/Trick

Simple and easy way to clear all the input fields in the form.[^]


您可以查看处理不同JavaScript验证的CP链接。



简化了JavaScript表单验证 [ ^ ]



希望这有帮助
You can check the CP link which handles different javascript validations.

JavaScript form validations made easy[^]

Hope this helps


我建​​议你使用Github提供的jquery验证引擎。它还将为您提供带有优雅错误消息的自定义验证。



您可以从给定链接中找到所有文档和来源:

https://github.com/posabsolute/jQuery-Validation-Engine [ ^ ]。



您可以体验链接上相同的演示:

http://www.position -relative.net/creation/formValidator/demos/demoValidators.html [ ^ ]。



我希望这会对你有帮助。
I suggest you to use the jquery validation engine given by Github. It will also provide you custom validations with elegant error messages.

You will find all documentation and source from the given link:
https://github.com/posabsolute/jQuery-Validation-Engine[^].

You can experience the demo for the same on link:
http://www.position-relative.net/creation/formValidator/demos/demoValidators.html[^].

I hope this will help you.


这篇关于使用java脚本在asp.net中验证文本框和下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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