Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2008, 05:23 AM
Authorized User
 
Join Date: Mar 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error running Javascript in IE 6

I have designed the asp page in IE 7 on Windows XP platform the is problem is that i am unable to run the page on client's PC.At client's place there is IE 6. It is giving javacript error 'Undefined' when submit button is clicked. Please tell me how should i tackle this problem. Following is the code of the page.

<% @ Language=VBScript%>


<%
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString
Set rsnew_appts = Server.CreateObject("ADODB.Recordset")
Set rsEmp_salary = Server.CreateObject("ADODB.Recordset")
Set rsTYPE = Server.CreateObject("ADODB.Recordset")
Set rsDIV = Server.CreateObject("ADODB.Recordset")
Set rsDESG = Server.CreateObject("ADODB.Recordset")
Set rsYear = Server.CreateObject("ADODB.Recordset")

session("module")=request.querystring("module")
session("prv")=request.querystring("prv")

etype=request.form("sel_Type")
if etype="" then
    etype=request.form("emp_type")
end if

div=request.form("sel_Division")
if div="" then
    div=request.form("DIVISION")
end if

edesg=request.form("sel_Desg")
if edesg="" then
    edesg=request.form("DESG")
end if

eyear=request.form("sel_year")
if eyear="" or eyear="select" then
    eyear=request.form("yr")
end if

sqlTYPE="select distinct type from dtype"
rsTYPE.Open sqlTYPE, Conn, adOpenStatic, adLockReadOnly, adCmdText
%>
<html>
<head>
<SCRIPT type="text/javascript" language="JavaScript">
function submitform()
{
    document.form1.submit();
}
function ApproveEmployee()
{
    var strcondition;
    strcondition=ListEmp(document.form2.chkEmp);
    if (strcondition!="")
    {
        var r=confirm("Are you sure you want to approve increment?");
        if (r==true)
        {
            document.form2.strcond_string.value=strcondition;
            document.form2.submit();
        }
    }
}
function ListEmp(field)
{
    try{
        var strcriteria;
        strcriteria="";

        for (i=0; i < field.length;i++)
        {
            if (field[i].checked==true)
            {
                strcriteria=strcriteria + " (prmn_id=" + document.form2.empid[i].value + " and emp_intdt='" + document.form2.emp_incr_dt[i].value + "') OR";
            }
            if (i==field.length-1)
            {
                strcriteria=Mid(strcriteria,0,String(strcriteria). length-3);
                if (strcriteria=="")
                {
                    alert("No employee is selected for approval");
                    strcriteria="";
                }
            }
        }
        if (field.length==undefined)
        {
            if (document.form2.chkEmp.checked==true)
            {
                strcriteria=" (prmn_id=" + document.form2.empid.value + " and emp_intdt='" + document.form2.emp_incr_dt.value + "') ";
            }
            else
            {
                strcriteria="";
            }
        }

        return strcriteria;
        }
        catch(e){
                alert("Error occured in script.\nError Name:" + e.name + "\nError message:" + e.message);
                return "";
                }
}
function Mid(str, start, len)
{
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}
</script>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style type="text/css">
.stylebr
{
    border-spacing:inherit;
    border:thin black inset;
    border-color:gray;
    border-width:1px;
}
.style15 {
    border-style: solid;
    border-width: 1px;
    border-collapse: collapse;
}
.style18 {
    border:1px inset gray;
    font-family: Verdana;
    font-size: 9pt;
        background-color: #DCDADC;
}
.style19 {
    border-style: solid;
    border-width: 1px;
    border-collapse: collapse;
    background-color: #DCDADC;
}
.style21 {
    font-family: Verdana;
}
.style22 {
    font-size: xx-small;
}
.style23 {
    border:1px inset gray;
    font-family: Verdana;
    font-size: 8pt;
        text-align: center;
    font-weight: bold;
    color: #400080;
}
.style27 {
    border:1px inset gray;
    font-family: Verdana;
    font-size: 7pt;
    color: #400080;
}
.style28 {
    border:1px inset gray;
    font-family: Verdana;
    font-size: 8pt;
    font-weight: bold;
    color: #400080;
}
.style29 {
    border:1px inset gray;
    font-family: Verdana;
    font-size: 7pt;
    color: #400080;
    text-align: center;
}
.style30 {
    margin-bottom: 0px;
}
.style31 {
    border-style: solid;
    border-width: 1px;
    border-collapse: collapse;
    text-align: center;
    color: #400080;
}
.style32 {
    color: #400080;
}
.style33 {
    font-size: xx-small;
    color: #400080;
}
.style34 {
    color: #4E009B;
}
</style>
<title>Increment Approval</title>
</head>
<body style="background-color: #EBE9EB">
<form name="form1" action="increment_approval.asp?module=<%=session(" module")%>&prv=<%=session("prv")%>" method="post" style="height: 54px" class="style30">
<table class="style18" height="30" style="border-style: solid">
    <tr>
        <td class="style31" valign="bottom" colspan="4"><strong>INCREMENT
        APPROVAL</strong></td>
        </tr>
    <tr>
        <td class="style15" valign="bottom"><span class="style33">Select Type:.
        </span><span class="style21"><span class="style22">
        <span class="style32">
        <select name="sel_Type" style="width: 105px" onchange="javascript:submitform();">
            <option selected>Select</option>
            <%if session("module")="HR" and session("prv")<5 then
                if etype="Field Force" then
                    ss="selected"
                else
                    ss=""
                end if
            %>
           <option <%=ss%> value="Field Force"><%Response.Write "Field Force"%>
            <%else
                    Do while not rsTYPE.eof
                        if etype="select" or etype="" then
                            if etype=rsTYPE("type") then
                                ss="selected"
                            else
                                ss=""
                            end if
                        else
                            if etype=rsTYPE("type") then
                                ss="selected"
                            else
                                ss=""
                            end if
                        end if
                    %>
                   <option <%=ss%> value="<%=rsTYPE("type")%>">
                   <%Response.Write(rsTYPE("type"))%>
                    <%
                    rsTYPE.Movenext
                      Loop
                      rsTYPE.close
                  end if
            %>
        </select></span></span></span></td>
        <%
        sqlDIV="select distinct dept from dtype where type='" & etype & "'"
        rsDIV.Open sqlDIV, Conn, adOpenStatic, adLockReadOnly, adCmdText
        %>
        <td class="style15" valign="bottom"><span class="style33">Select
        Division:.
        </span><span class="style21"><span class="style22">
        <span class="style32">
        <select name="sel_Division" onchange="javascript:submitform();" style="width: 243px; height: 13px;">
            <option>Select</option>
            <%
                Do while rsDiv.eof=false
                    if div="select" or div="" then
                        if div=rsDiv("dept") then
                            ss="selected"
                        else
                            ss=""
                        end if
                    else
                        if div=rsDiv("dept") then
                            ss="selected"
                        else
                            ss=""
                        end if
                    end if
            %>
                <option <%=ss%> value="<%=rsDIV("dept")%>">
                   <%Response.Write(rsDIV("dept"))%>
            <%
                    rsDiv.movenext
                loop
            %>
        </select></span></span></span></td>
        <%
        sqlDesg="select distinct dep_desg from dtype where type='" & etype & "' and dept='" & div & "'"
        rsDesg.Open sqlDesg, Conn, adOpenStatic, adLockReadOnly, adCmdText
        %>
        <td class="style15" valign="bottom" style="width: 143px">
        <span class="style33">Select Desg:.</span><span class="style21"><span class="style22"><span class="style34"><span class="style32"><select name="sel_Desg" style="width: 109px; height: 5px" onchange="javascript:submitform();">
            <option selected>Select</option>
            <%
                Do while rsDESG.eof=false
                    if edesg="select" or edesg="" then
                        if edesg=rsDESG("dep_desg") then
                            ss="selected"
                        else
                            ss=""
                        end if
                    else
                        if edesg=rsDESG("dep_desg") then
                            ss="selected"
                        else
                            ss=""
                        end if
                    end if
            %>
                <option <%=ss%> value="<%=rsDESG("dep_desg")%>">
                   <%Response.Write(rsDESG("dep_desg"))%>
            <%
                    rsDESG.movenext
                loop
            %>
        </select></span></span></span></span></td>
        <%
            sqlYear="select distinct year(entry_date) as yr from new_appointments where emp_type='" & etype & "' and emp_division='" & div & "' and emp_desg='" & edesg & "'"
            rsYear.Open sqlYear, Conn, adOpenStatic, adLockReadOnly, adCmdText
        %>
        <td class="style15"><span class="style33">Select Year:. </span><span class="style21"><span class="style22">
        <span class="style32">
        <select size="1" name="sel_year" class="style77" style="width:78px; height: 9px;" onchange="javascript:submitform();">
        <option selected>Select</option>
        <%
            Do while not rsYear.eof
                if ucase(eyear)="SELECT" then
                    if eyear=rsYear("yr") or eyear="" then
                        aa="selected"
                    else
                        aa=""
                    end if
                    aa=""
                else
                    if cint(eyear)=rsYear("yr") then
                        aa="selected"
                    else
                        aa=""
                    end if
                end if
        %>
                <option <%=aa%> value="<%=rsYear("yr")%>">
                <%response.write rsYear("yr")%>
        <%
                rsYear.Movenext
              Loop
              rsYear.close
        %></select></span></span></span><span class="style32">
        <input type="hidden" name="emp_type" value="<%=etype%>">
        <input type="hidden" name="DIVISION" value="<%=div%>">
        <input type="hidden" name="DESG" value="<%=edesg%>">
        <input type="hidden" name="yr" value="<%=eyear%>">
        </span>
        </td></tr>
</table>
</form>
<table width="100%" class="style19" style="border-style: solid" height="45">
    <form name="form2" action="approve_incr.asp?module=<%=session("module ")%>&prv=<%=session("prv")%>" method="post" style="height: 68px">
    <tr>
        <td style="width: 22px; height: 30px;" class="style28">Sr No.</td>
        <td style="width: 51px; height: 30px;" class="style28">Emp. Code</td>
        <td style="width: 222px; height: 30px;" nowrap="nowrap" class="style28">
        Emp. Name</td>
        <td class="style23" style="height: 30px; width: 97px;">Division</td>
        <td style="width: 200px; height: 30px;" nowrap="nowrap" class="style23">
        HQ</td>
        <td class="style23" style="width: 91px; height: 30px;">Incr. Date.</td>
        <td class="style23" style="width: 91px; height: 30px;">Incr. Amt.</td>
        <td class="style23" style="height: 30px">Aprroved</td>
    </tr>
<%
if request.form("sel_type") <>"Select" and request.form("sel_Division")<>"Select" and request.form("sel_desg")<>"Select" and request.form("sel_year")<>"Select" then
    i=0
    j=0
    With rsnew_appts
        .Open "Select prmn_id,emp_name,emp_division,emp_hq,basic,fda,vda ,adv_allowance,hra,edu_all,conv_all," & _
        "med_all,cash_lta,oth_pay,reinb_info,spl_all,cash, cca,da,tour_all,overnight," & _
        "yr_med_all,yr_lta,appr_stat,emp_stat,emp_intd t from new_appointments where entry_flag=6 and " & _
        "emp_type='" & etype & "' and emp_division='" & div & "' and emp_desg='" & edesg & "' and year(emp_intdt)=" & CInt(eyear) & " Order by appr_stat,prmn_id,emp_intdt", conn, adOpenStatic, adLockReadOnly
        If .EOF = False Then
            Do While .EOF = False
                If lcase(.fields("emp_stat"))="false" then ''fasle - 0
                    sqlEmp_Salary="Select prmn_id,basic,fda,vda,adv_allowance,hra,edu_all,co nv_all,med_all,cash_lta,oth_pay,reinb_info,spl_all ,cash,cca,yr_med_all,yr_lta from emp_salary where prmn_id=" & rsnew_appts.Fields("prmn_id")
                ElseIf lcase(.fields("emp_stat"))="true" then ''true - 1
                    sqlEmp_Salary="Select Top 1 prmn_id,incr_date,basic,fda,vda,adv_allowance,hra, edu_all,conv_all,med_all,cash_lta,oth_pay,reinb_in fo,spl_all,cash,cca,yr_med_all,yr_lta from emp_sal_history where prmn_id=" & rsnew_appts.Fields("prmn_id") & " and incr_date<>'"& rsnew_appts.Fields("emp_intdt") &"' order by incr_date desc"
                End If
                With rsEmp_salary
                    If .State = adStateOpen Then .Close
                    .Open sqlEmp_Salary, conn, adOpenStatic, adLockReadOnly
                    If .EOF = False Then
                        increment_amt = (rsnew_appts("basic") - rsEmp_salary("basic")) + _
                        (rsnew_appts("fda") - rsEmp_salary("fda")) + _
                        (rsnew_appts("vda") - rsEmp_salary("vda")) + _
                        (rsnew_appts("adv_allowance") - rsEmp_salary("adv_allowance")) + _
                        (rsnew_appts("hra") - rsEmp_salary("hra")) + _
                        (rsnew_appts("edu_all") - rsEmp_salary("edu_all")) + _
                        (rsnew_appts("conv_all") - rsEmp_salary("conv_all")) + _
                        (rsnew_appts("oth_pay") - rsEmp_salary("oth_pay")) + _
                        (rsnew_appts("reinb_info") - rsEmp_salary("reinb_info")) + _
                        (rsnew_appts("spl_all") - rsEmp_salary("spl_all")) + _
                        (rsnew_appts("cash") - rsEmp_salary("cash")) + _
                        (rsnew_appts("cca") - rsEmp_salary("cca"))

                        If rsnew_appts("med_all") = 0 Then
                            increment_amt = increment_amt + ((rsnew_appts("yr_med_all") / 12) - (rsEmp_salary("yr_med_all") / 12))
                        Else
                            increment_amt = increment_amt + (rsnew_appts("med_all") - rsEmp_salary("med_all"))
                        End If
                        If rsnew_appts("cash_lta") = 0 Then
                            increment_amt = increment_amt + ((rsnew_appts("yr_lta") / 12) - (rsEmp_salary("yr_lta") / 12))
                        Else
                           increment_amt = increment_amt + (rsnew_appts("cash_lta") - rsEmp_salary("cash_lta"))
                        End If
                    Else
                        increment_amt = 0
                    End If
                End With
                i=i+1

                if rsnew_appts.Fields("appr_stat")=2 then
                    ss="#DEDBDE"
                else
                    ss="white"
                end if
                %>
                <tr id="tblrow">
                    <td style="width: 22px; height: 5px" class="style29" bgcolor="<%=ss%>"><%=i%></td>
                    <td style="width: 51px; height: 5px" class="style29" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("prmn_id") %></td>
                    <td style="width: 222px; height: 5px" nowrap="nowrap" class="style27" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("emp_name" )%></td>
                    <td class="style27" style="width: 97px; height: 5px" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("emp_divis ion")%></td>
                    <td style="width: 200px; height: 5px" nowrap="nowrap" class="style27" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("emp_hq")% ></td>
                    <td class="style29" style="width: 91px; height: 5px" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("emp_intdt ")%></td>
                    <td class="style29" style="width: 91px; height: 5px" bgcolor="<%=ss%>"><%=increment_amt%></td>
                    <td class="style29" bgcolor="<%=ss%>" style="height: 5px">
                    <%if rsnew_appts.Fields("appr_stat")=2 then%>
                        <input type="checkbox" name="chkdisabled" disabled checked>
                    <%else%>
                        <input type="checkbox" name="chkEmp" id=<%=j%>>
                        <input type="hidden" name="empid" id=<%=j%> value=<%=rsnew_appts.Fields("prmn_id")%>>
                        <input type="hidden" name="emp_incr_dt" id=<%=j%> value=<%=rsnew_appts.Fields("emp_intdt")%>>
                    <%j=j+1
                    end if%> </td></tr>
<%
                .MoveNext
            Loop
        End If
    End With
end if%>
    <tr><td class="style29" bgcolor="<%=ss%>" colspan="9">
        <input name="update" type="button" value="submit" onclick="javascript:ApproveEmployee();">
        <input name="strcond_string" type="hidden">
        </td></tr>
    </form>
</table>
</body>
<%conn.close%>
</html>

987654321
__________________
987654321
 
Old July 3rd, 2008, 05:32 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Very difficult to help with this sort of mis-mash of HTML, ASP and JavaScript.
Two suggestions:
* Set up debugging on the machine that's failing by unchecking "disable script debugging" in IE's advanced options tab and make sure there is a debugger installed, Office has one.

* Post the actual HTMl you can see in the view-source. At least then we can test the page somewhat ourselves or at least open it in an editor which would help readability.

--

Joe (Microsoft MVP - XML)
 
Old July 5th, 2008, 04:58 AM
Authorized User
 
Join Date: Mar 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alright i am condensing the code where exactly the error arises.

It is containing a table where it list the employee details and every employee record is having a single checkbox. I am fetching the data form database
if the "appr_stat" field value=2 then i add the disabled checked checkbox
else i add the unchecked checkbox.
Now according to the number of checkbox are checked by the user i collect employee prmn_id.For this i am creating checkbox group and passing unique id value.The name of the checkbox is chkEmp.

     When page is submitted i am calling javascript function (javascript:ApproveEmployee()).It is giving error there.I think it is giving error at document.form2.chkEmp

This page is running properly on Windows XP Profession but not on Windows 98

In the following code i have only specified the code where javascript function is defind and the checkbox whose value are not getting accessed i.e chkEmp

Please tell me how should i spot the error.

<% @ Language=VBScript%>
<html><head><SCRIPT type="text/javascript" language="JavaScript">
function submitform()
{
    document.form1.submit();
}
function ApproveEmployee()
{
    var strcondition;
    strcondition=ListEmp(document.form2.chkEmp);
    if (strcondition!="")
    {
        var r=confirm("Are you sure you want to approve increment?");
        if (r==true)
        {
            document.form2.strcond_string.value=strcondition;
            document.form2.submit();
        }
    }
}
function ListEmp(field)
{
    try{
        var strcriteria;
        strcriteria="";

        for (i=0; i < field.length;i++)
        {
            if (field[i].checked==true)
            {
                strcriteria=strcriteria + " (prmn_id=" + document.form2.empid[i].value + " and emp_intdt='" + document.form2.emp_incr_dt[i].value + "') OR";
            }
            if (i==field.length-1)
            {
                strcriteria=Mid(strcriteria,0,String(strcriteria). length-3);
                if (strcriteria=="")
                {
                    alert("No employee is selected for approval");
                    strcriteria="";
                }
            }
        }
        if (field.length==undefined)
        {
            if (document.form2.chkEmp.checked==true)
            {
                strcriteria=" (prmn_id=" + document.form2.empid.value + " and emp_intdt='" + document.form2.emp_incr_dt.value + "') ";
            }
            else
            {
                strcriteria="";
            }
        }

        return strcriteria;
        }
        catch(e){
                alert("Error occured in script.\nError Name:" + e.name + "\nError message:" + e.message);
                return "";
                }
}
function Mid(str, start, len)
{
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}
</script>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body style="background-color: #EBE9EB">
<form name="form2" action="approve_incr.asp?module=<%=session("module ")%>&prv=<%=session("prv")%>" method="post" style="height: 68px">
<table width="100%" class="style19" style="border-style: solid" height="45">
    <tr><td style="width: 22px; height: 30px;" class="style28">Sr No.</td>
        <td style="width: 51px; height: 30px;" class="style28">Emp. Code</td>
        <td style="width: 222px; height: 30px;" nowrap="nowrap" class="style28">Emp. Name</td>
        <td class="style23" style="height: 30px">Aprroved</td></tr>
    <tr id="tblrow">
        <td style="width: 22px; height: 5px" class="style29" bgcolor="<%=ss%>"><%=i%></td>
        <td style="width: 51px; height: 5px" class="style29" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("prmn_id") %></td>
        <td style="width: 222px; height: 5px" nowrap="nowrap" class="style27" bgcolor="<%=ss%>"><%=rsnew_appts.Fields("emp_name" )%></td>
        <td class="style29" bgcolor="<%=ss%>" style="height: 5px">
        <%if rsnew_appts.Fields("appr_stat")=2 then%>
            <input type="checkbox" name="chkdisabled" disabled checked>
        <%else%>
            <input type="checkbox" name="chkEmp" id=<%=j%>>
            <input type="hidden" name="empid" id=<%=j%> value=<%=rsnew_appts.Fields("prmn_id")%>>
            <input type="hidden" name="emp_incr_dt" id=<%=j%> value=<%=rsnew_appts.Fields("emp_intdt")%>>
        <%j=j+1
        end if%> </td></tr>
    <tr><td class="style29" bgcolor="<%=ss%>" colspan="9">
        <input name="update" type="button" value="submit" onclick="javascript:ApproveEmployee();">
        <input name="strcond_string" type="hidden"></td></tr>
</table></form></body></html>


Thanks in Advance

987654321
 
Old July 5th, 2008, 06:19 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I suggested two ways to help spot the error, you have done neither. To re-iterate either post the ACTUAL HTML that the browser sees. This means there will be no server-side code and we can test it ourselves or better still debug the problem in situ.

Another thing is that checkboxes should not have the same name as they are not grouped like radio buttons. You should give each its own name and/or id and then use something like getElementsByTagName("checkbox") to retrieve them and loop through them. You can check the name to see if it matches chkEmpx where x is a digit and then take the appropriate action.

--

Joe (Microsoft MVP - XML)
 
Old July 7th, 2008, 01:08 AM
Authorized User
 
Join Date: Mar 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If this is a case,then why does it works on Windows XP professional.

987654321





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error - Running examples BadKarma BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 0 October 31st, 2007 05:44 PM
Running a Javascript form in ASP.NET:problem Nostromo77 ASP.NET 2.0 Basics 2 February 5th, 2007 09:01 PM
Error while running javascript code in ASP.NET Pag fozia_izhar ASP.NET 1.0 and 1.1 Professional 2 December 20th, 2006 03:39 AM
Getting error while running CaseStudy Project badercheema BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 March 27th, 2006 03:25 PM
DTS running error Jane SQL Server DTS 0 February 9th, 2004 02:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.