开发者

asp and javascript message alert doesn't work

here's my code

<%
if request.form("Add") = "  Add  " then

        if request.form("txtdistributor") = "" or request.form("sinumber") = "" or request.form("tstdate") = "" or request.form("drnumber") = "" or request.form("drdate") = "" or request.form("receivedby") = "" then
        response.redirect("salesinvoice.asp?userloggedin=" &request.querystring("userloggedin") &"&dist=" &request.QueryString("dist") ) 
        end if


            SQLString = "INSERT INTO salesinvoice (distributor,sidate,sinumber) VALUES ('" & Request.form("txtdistributor") & "','" & Request.Form("tstdate") & "','" & Request.Form("sinumber") &"') "

            set DBConn = Server.CreateObject("ADODB.Connection")
            DBConn.Open Application("dals_ConnectionString")

            DBConn.Execute(SQLString)
            DBConn.Close


            set DBConn = Server.CreateObject("ADODB.Connection")
            DBConn.Open Application("dals_ConnectionString")
            SQLString = "INSERT INTO Delivery_Receipt (Date_Purchase, Receipt_no, Distributor, Received_by, Entry_Date,sinumber) VALUES"
            SQLString = SQLString & "('" & Request.Form("drdate") & "','" & Request.Form("drnumber") & "', '" & Request.Form("txtdistributor")& "','" & Request.Form("receivedby") & "','" & now() & "','" & request.Form("sinumber") & "')"

            DBConn.Execute(SQLString)
            DBConn.Close



response.Redirect("salesinvoice.asp?userloggedin=" &request.QueryString("userloggedin") &"&dist=" &request.QueryString("dist"))

end if
%>


<!-- Javascript -->
<script type="text/javascript">

function validateform()
{
    if (document.frm.txtdistributor.value == '')
    {
    alert('Please input distributor');
    document.frm.txtdistributor.focus();
    return false;
    }
    if (document.frm.txtdistributor.value == '')
    {
    alert('Please input distributor');
    document.frm.txtdistributor.focus();
    return false;
    }   
    if (document.frm.sinumber.value == '')
    {
    alert('Please input sales invoice number');
    document.frm.sinumber.focus();
    return false;
    }
    if (document.frm.tstdate.value == '')
    {
    alert('Please input sales invoice date');
    document.frm.tstdate.focus();
    return false;
    }
    if (document.frm.drnumber.value == '')
    {
    alert('Please input Delivery Receipt Number');
    document.frm.drnumber.focus();
    return false;
    }   
    if (document.frm.drdate.value == '')
    {
    alert('Please input Delivery Receipt');
    document.frm.drdate.focus();
    return false;
    }
    if (document.frm.receivedby.value == '')
    {
    alert('Please input requestor');
    document.frm.receivedby.focus();
    return false;
    }
return true;
}
</script>
<html>
    <head>
        <title>Sales Invoice</title>
    </head>
<body>

<!--#include file="header.asp"-->
<form name="frm" id="frm" action="salesinvoice.asp?userloggedin=<%=request.QueryString("userloggedin")%>&dist=<%=request.QueryString("dist")%>" method="post" onSubmit="return validateform();">

<link href="css/calendar.css" rel="stylesheet" type="text/css">
 <script type="text/javascript" src="calendar_date_picker.js"></script>
 <script type="text/javascript">
 var cdp1 = new CalendarDatePicker();
 var props = {
    debug :         true,
    excludeDays :       [6,0,1],
    excludeDates :      ['20081225','20081226','20091225','20091226'],
    minimumFutureDate : 5,
    formatDate :        '%m-%d-%y'
    };
 var cdp2 = new CalendarDatePicker(props);
 props.formatDate = '%d-%m-%y';
 var cdp3 = new CalendarDatePicker(props);
 cdp3.endYear = cdp3.startYear + 1;
 </script>开发者_C百科;

<table width="900" align="center">
    <tr>
        <td width="200">Distributor</td>
        <td>

    <%if request.querystring("dist") <> "yes" then%>

        <select name="txtdistributor"  style="width:260;">
        <option value="">- Select -</option>
         <%
            strsql = "select Distinct(Distributor) from salesinvoice"
            set rsdist = server.createobject("adodb.recordset")
            rsdist.open strsql,application("dals_connectionstring")

            while not rsdist.eof
         %> 

            <option value="<%=rsdist("distributor")%>"><%=rsdist("distributor")%></option>

        <%
        rsdist.movenext
        wend

        rsdist.close
        set rsdist = nothing
        %>
    </select>&nbsp;<a href="salesinvoice.asp?UserLoggedIn=<%=request.QueryString("UserLoggedIn")%>&dist=yes">Add New Distributor</a>
    <%end if%>

    <%if request.querystring("dist") <> "no" then%>
        <input type="text" size="38" name="txtdistributor" id="txtdistributor">&nbsp;<a href="salesinvoice.asp?UserLoggedIn=<%=request.QueryString("UserLoggedIn")%>&dist=no">[ - ]</a>   
    <%end if%>

        </td> 
    </tr>
    <tr>
        <td>SI Number</td>
        <td><input type="text" name="sinumber" id="sinumber"></td>
    </tr>
    <tr>
        <td>SI Date</td>
        <td><input type="text" name="tstdate" id="txtdate" readonly>&nbsp;<a href="#" onClick="cdp1.showCalendar(this, 'txtdate'); return false;"><img src="images/calendar.png" border="0" align="absmiddle" style="cursor:hand;" title="Calendar"></a></td>
    </tr>
    <tr>
        <td>DR Number</td>
        <td><input type="text" name="drnumber" id="drnumber"></td>
    </tr>
    <tr>
        <td>DR date</td>
        <td><input type="text" name="drdate" id="drdate" readonly>&nbsp;<a href="#" onClick="cdp1.showCalendar(this, 'drdate'); return false;"><img src="images/calendar.png" border="0" align="absmiddle" style="cursor:hand;" title="Calendar"></a></td>
    </tr>
    <tr>
        <td>Received by</td>
        <td>
        <!--<input type="text" name="receivedby" id="receivedby">-->
        <select name="receivedby" id="receivedby">
            <option value="">- Select -</option>
            <%
            strsql = "select first_name,last_name from sysadusers"
            set rsname = server.CreateObject("adodb.recordset")
            rsname.open strsql,application("dals_connectionstring")

            while not rsname.eof
            %>
                <option value="<%=rsname("first_name")%>, <%=rsname("last_name")%>"><%=rsname("first_name")%>, <%=rsname("last_name")%></option>
            <%
            rsname.movenext
            wend

            rsname.close
            %>

        </select>


You might have runtime error in the validation function, for example when the form does not contain the txtdistributor drop down.

For the sake of debugging, change the function to this only:

function validateform() {
   alert("validation started");
   var oDDL = document.frm.txtdistributor;
   if (oDDL) {
      if (oDDL.value == '') {
         alert('Please input distributor');
         oDDL.focus();
      }
   } else {
      alert("form does not contain txtdistributor");
   }
   alert("validation ended");

   return false;
}

If this works, apply the same logic for the rest of the fields and remove the debug messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜