| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1273 人关注过本帖
标题:如何修改表单填写中的必填项为任填项?
只看楼主 加入收藏
gytl
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-4-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
如何修改表单填写中的必填项为任填项?
代码如下:

<%
Sub ProductEdit()
    Dim Action, rsRepeat, rs, sql
    Action = request.QueryString("Action")
    If Action = "SaveEdit" Then
        Set rs = server.CreateObject("adodb.recordset")
        If Len(Trim(request.Form("ProductName")))<1 Then
            response.Write ("<script language='javascript'>alert('请填写产品名称!');history.back(-1);</script>")
            response.End
        End If
        If Request.Form("SortID") = "" And Request.Form("SortPath") = "" Then
            response.Write ("<script language='javascript'>alert('请选择所属分类!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("ProductModel")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写产品型号!');history.back(-1);</script>")
            response.End
        End If
        If (Not IsNumeric(Trim(request.Form("N_Price")))) Or (Not IsNumeric(Trim(request.Form("P_Price"))))Then
            response.Write ("<script language='javascript'>alert('请正确填写市场价格、批发价格!');history.back(-1);</script>")
            response.End
        ElseIf Trim(request.Form("N_Price"))<0 Or Trim(request.Form("P_Price"))<0then
            response.Write ("<script language='javascript'>alert('请正确填写市场价格、批发价格!');history.back(-1);</script>")
            response.End
        End If
        If (Not IsNumeric(Trim(request.Form("Stock")))) Then
            response.Write ("<script language='javascript'>alert('请填写/选择库存数量!');history.back(-1);</script>")
            response.End
        End If
        If Len(Trim(Request.Form("Unit"))) = 0 Then
            response.Write ("<script language='javascript'>alert('请填写/选择产品单位!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("Maker")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写出品公司!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("SmallPic")) = "" Then
            response.Write ("<script language='javascript'>alert('请上传产品小图!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("BigPic")) = "" Then
            response.Write ("<script language='javascript'>alert('请上传产品大图!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("Content")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写产品详细介绍!');history.back(-1);</script>")
            response.End
        End If
        If Result = "Add" Then
            Set rsRepeat = conn.Execute("select ProductNo from Qianbo_Products where ProductNo='" & Trim(Request.Form("ProductNo")) & "'")
            If Not (rsRepeat.bof And rsRepeat.EOF) Then
                response.Write "<script language='javascript'>alert('" & Trim(Request.Form("ProductNo")) & "产品编号已存在!');history.back(-1);</script>"
                response.End
            End If
            rsRepeat.Close
            Set rsRepeat = Nothing
            sql = "select * from Qianbo_Products"
            rs.Open sql, conn, 1, 3
            rs.addnew
            rs("ProductName") = Trim(Request.Form("ProductName"))
            If Request.Form("ViewFlag") = 1 Then
                rs("ViewFlag") = Request.Form("ViewFlag")
            Else
                rs("ViewFlag") = 0
            End If
            rs("SortID") = Request.Form("SortID")
            rs("SortPath") = Request.Form("SortPath")
            rs("ProductNo") = Trim(Request.Form("ProductNo"))
            rs("ProductModel") = Trim(Request.Form("ProductModel"))
            rs("N_Price") = Round(Trim(Request.Form("N_Price")), 2)
            rs("P_Price") = Round(Trim(Request.Form("P_Price")), 2)
            rs("Stock") = Round(Trim(Request.Form("Stock")), 2)
            rs("Unit") = Trim(Request.Form("Unit"))
            rs("Maker") = Trim(Request.Form("Maker"))
            If Request.Form("CommendFlag") = 1 Then
                rs("CommendFlag") = Request.Form("CommendFlag")
            Else
                rs("CommendFlag") = 0
            End If
            If Request.Form("NewFlag") = 1 Then
                rs("NewFlag") = Request.Form("NewFlag")
            Else
                rs("NewFlag") = 0
            End If
            GroupIdName = Split(Request.Form("GroupID"), "┎╂┚")
            rs("GroupID") = GroupIdName(0)
            rs("Exclusive") = Trim(Request.Form("Exclusive"))
            rs("SmallPic") = Trim(Request.Form("SmallPic"))
            rs("BigPic") = Trim(Request.Form("BigPic"))
            rs("Content") = RTrim(Request.Form("Content"))
            rs("AddTime") = Now()
            rs("UpdateTime") = Now()
            rs("SeoKeywords") = Trim(Request.Form("SeoKeywords"))
            rs("SeoDescription") = Trim(Request.Form("SeoDescription"))
            rs.update
            rs.Close
            Set rs = Nothing
        End If
        If Result = "Modify" Then
            sql = "select * from Qianbo_Products where ID="&ID
            rs.Open sql, conn, 1, 3
            rs("ProductName") = Trim(Request.Form("ProductName"))
            If Request.Form("ViewFlag") = 1 Then
                rs("ViewFlag") = Request.Form("ViewFlag")
            Else
                rs("ViewFlag") = 0
            End If
            rs("SortID") = Request.Form("SortID")
            rs("SortPath") = Request.Form("SortPath")
            rs("ProductNo") = Trim(Request.Form("ProductNo"))
            rs("ProductModel") = Trim(Request.Form("ProductModel"))
            rs("N_Price") = Round(Trim(Request.Form("N_Price")), 2)
            rs("P_Price") = Round(Trim(Request.Form("P_Price")), 2)
            rs("Stock") = Round(Trim(Request.Form("Stock")), 2)
            rs("Unit") = Trim(Request.Form("Unit"))
            rs("Maker") = Trim(Request.Form("Maker"))
            If Request.Form("CommendFlag") = 1 Then
                rs("CommendFlag") = Request.Form("CommendFlag")
            Else
                rs("CommendFlag") = 0
            End If
            If Request.Form("NewFlag") = 1 Then
                rs("NewFlag") = Request.Form("NewFlag")
            Else
                rs("NewFlag") = 0
            End If
            GroupIdName = Split(Request.Form("GroupID"), "┎╂┚")
            rs("GroupID") = GroupIdName(0)
            rs("Exclusive") = Trim(Request.Form("Exclusive"))
            rs("SmallPic") = Trim(Request.Form("SmallPic"))
            rs("BigPic") = Trim(Request.Form("BigPic"))
            rs("Content") = RTrim(Request.Form("Content"))
            rs("UpdateTime") = Now()
            rs("SeoKeywords") = Trim(Request.Form("SeoKeywords"))
            rs("SeoDescription") = Trim(Request.Form("SeoDescription"))
            rs.update
            rs.Close
            Set rs = Nothing
        End If
        response.Write "<script language='javascript'>alert('设置成功!');location.replace('ProductList.Asp');</script>"
    Else
        If Result = "Modify" Then
            Set rs = server.CreateObject("adodb.recordset")
            sql = "select * from Qianbo_Products where ID="& ID
            rs.Open sql, conn, 1, 1
            If rs.bof And rs.EOF Then
                response.Write ("<center>数据库记录读取错误!</center>")
                response.End
            End If
            ProductName = rs("ProductName")
            ViewFlag = rs("ViewFlag")
            SortName = SortText(rs("SortID"))
            SortID = rs("SortID")
            SortPath = rs("SortPath")
            ProductNo = rs("ProductNo")
            ProductModel = rs("ProductModel")
            N_Price = rs("N_Price")
            P_Price = rs("P_Price")
            Stock = rs("Stock")
            Unit = rs("Unit")
            Maker = rs("Maker")
            CommendFlag = rs("CommendFlag")
            NewFlag = rs("NewFlag")
            GroupID = rs("GroupID")
            Exclusive = rs("Exclusive")
            SmallPic = rs("SmallPic")
            BigPic = rs("BigPic")
            Content = rs("Content")
            SeoKeywords = rs("SeoKeywords")
            SeoDescription = rs("SeoDescription")
            rs.Close
            Set rs = Nothing
        Else
            Randomize Timer
            ProductNo = Hour(Now)&Minute(Now)&Second(Now)&"-"&Int(900 * Rnd) + 100
            Stock = 10000
        End If
    End If
End Sub

Sub SelectGroup()
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "select GroupID,GroupName from Qianbo_MemGroup"
    rs.Open sql, conn, 1, 1
    If rs.bof And rs.EOF Then
        response.Write("未设组别")
    End If
    While Not rs.EOF
        response.Write("<option value='"&rs("GroupID")&"┎╂┚"&rs("GroupName")&"'")
        If GroupID = rs("GroupID") Then response.Write ("selected")
        response.Write(">"&rs("GroupName")&"</option>")
        rs.movenext
    Wend
    rs.Close
    Set rs = Nothing
End Sub

Function SortText(ID)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Qianbo_ProductSort where ID="&ID
    rs.Open sql, conn, 1, 1
    SortText = rs("SortName")
    rs.Close
    Set rs = Nothing
End Function
%>
搜索更多相关主题的帖子: 任填项 表单 
2010-04-01 12:40
gytl
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-4-1
收藏
得分:0 
请高手帮忙,谢谢啊。
图片附件: 游客没有浏览图片的权限,请 登录注册
2010-04-02 09:48
gytl
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-4-1
收藏
得分:0 
上面表单带红*的必填,想不填或填文字都不行。
2010-04-02 09:51
sky222
Rank: 4
等 级:业余侠客
威 望:1
帖 子:152
专家分:225
注 册:2010-3-11
收藏
得分:5 
If Len(Trim(request.Form("ProductName")))<1 Then
            response.Write ("<script language='javascript'>alert('请填写产品名称!');history.back(-1);</script>")
            response.End
        End If
        If Request.Form("SortID") = "" And Request.Form("SortPath") = "" Then
            response.Write ("<script language='javascript'>alert('请选择所属分类!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("ProductModel")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写产品型号!');history.back(-1);</script>")
            response.End
        End If
        If (Not IsNumeric(Trim(request.Form("N_Price")))) Or (Not IsNumeric(Trim(request.Form("P_Price"))))Then
            response.Write ("<script language='javascript'>alert('请正确填写市场价格、批发价格!');history.back(-1);</script>")
            response.End
        ElseIf Trim(request.Form("N_Price"))<0 Or Trim(request.Form("P_Price"))<0then
            response.Write ("<script language='javascript'>alert('请正确填写市场价格、批发价格!');history.back(-1);</script>")
            response.End
        End If
        If (Not IsNumeric(Trim(request.Form("Stock")))) Then
            response.Write ("<script language='javascript'>alert('请填写/选择库存数量!');history.back(-1);</script>")
            response.End
        End If
        If Len(Trim(Request.Form("Unit"))) = 0 Then
            response.Write ("<script language='javascript'>alert('请填写/选择产品单位!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("Maker")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写出品公司!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("SmallPic")) = "" Then
            response.Write ("<script language='javascript'>alert('请上传产品小图!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("BigPic")) = "" Then
            response.Write ("<script language='javascript'>alert('请上传产品大图!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("Content")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写产品详细介绍!');history.back(-1);</script>")
            response.End
        End If
你把这里的注释起来,应该就好了
2010-04-02 10:40
gytl
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-4-1
收藏
得分:0 
回复 4楼 sky222
如何注释啊,我不会(惭愧)。您能帮改一下吗?只要改“产品价格”、“批发价格”和“库存数量”三项为不必填或者可以填文字(原来只能填数字,否则报错)就行。谢谢您。
2010-04-03 10:38
zhuyunshen
Rank: 6Rank: 6
等 级:侠之大者
威 望:2
帖 子:212
专家分:455
注 册:2009-11-22
收藏
得分:5 
ffgdsgd
2010-04-03 11:56
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:5 
        If Len(Trim(request.Form("ProductName")))<1 Then
            response.Write ("<script language='javascript'>alert('请填写产品名称!');history.back(-1);</script>")
            response.End
        End If
        If Request.Form("SortID") = "" And Request.Form("SortPath") = "" Then
            response.Write ("<script language='javascript'>alert('请选择所属分类!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("ProductModel")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写产品型号!');history.back(-1);</script>")
            response.End
        End If
        If (Not IsNumeric(Trim(request.Form("N_Price")))) Or (Not IsNumeric(Trim(request.Form("P_Price"))))Then
            response.Write ("<script language='javascript'>alert('请正确填写市场价格、批发价格!');history.back(-1);</script>")
            response.End
        ElseIf Trim(request.Form("N_Price"))<0 Or Trim(request.Form("P_Price"))<0then
            response.Write ("<script language='javascript'>alert('请正确填写市场价格、批发价格!');history.back(-1);</script>")
            response.End
        End If
        If (Not IsNumeric(Trim(request.Form("Stock")))) Then
            response.Write ("<script language='javascript'>alert('请填写/选择库存数量!');history.back(-1);</script>")
            response.End
        End If
        If Len(Trim(Request.Form("Unit"))) = 0 Then
            response.Write ("<script language='javascript'>alert('请填写/选择产品单位!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("Maker")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写出品公司!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("SmallPic")) = "" Then
            response.Write ("<script language='javascript'>alert('请上传产品小图!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("BigPic")) = "" Then
            response.Write ("<script language='javascript'>alert('请上传产品大图!');history.back(-1);</script>")
            response.End
        End If
        If LTrim(request.Form("Content")) = "" Then
            response.Write ("<script language='javascript'>alert('请填写产品详细介绍!');history.back(-1);</script>")
            response.End
        End If
这段就是验证输入的代码,把这段代码注释掉或临时删除。
2010-04-03 12:42
nicechlk
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:330
专家分:187
注 册:2008-9-6
收藏
得分:5 
为什么不用js来进行验证呢?

莫以善小而不为,莫以恶小而为之!
2010-04-05 15:14
快速回复:如何修改表单填写中的必填项为任填项?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020623 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved