www.webdeveloper.com
Results 1 to 2 of 2

Thread: conversion from vbscript to jscript

  1. #1
    Join Date
    Mar 2005
    Posts
    44

    conversion from vbscript to jscript

    hi guys, I tried to convert the following code from vbscript to jscript but there are still a few mistakes, i highlighted the areas in bold. I hope you can help.

    Code:
    <%
    Dim conn, rs, strSQL
    set conn = Server.CreateObject("ADODB.Connection")
    conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE =  " & Server.MapPath("db1.mdb"))
    If Request.Form("update") = "update" Then
     For each fld in Request.Form
      If Left(fld,7) = "status_" Then
       student_id = CLng(Mid(fld,8))
       attendance = Request.Form(fld)
       strSQL = "Update tblattend SET att_status = '" & attendance & "' WHERE studentID = " & student_id & " AND att_date = Date()"
       conn.Execute strSQL, recsupdated 
       If recsupdated = 0 Then
        conn.Execute "Insert INTO tblattend(studentID,att_status,att_date) VALUES(" & student_id & ",'" & attendance & "', #" _
        & Month(Date()) & "/" & Day(Date()) & "/" & Year(Date()) & "#)"
       End If
      End If
     Next
    End If
     
    set rs = conn.Execute("Select tblstudent.*, tblattend.att_status From tblstudent LEFT JOIN tblattend ON (tblstudent.studentID = tblattend.studentID AND tblattend.att_date = Date()) ORDER by tblstudent.Name")
    
    Function currentstatus(statval)
     If rs("att_status") = statval Then
      currentstatus = "checked"
     Else
      currentstatus = ""
     End If
     End Function
    %>
    <div align="center"><strong><font size="3">Attendance records for today</font></strong></div>
    <form name="form1" method="post" action="">
      <table width="50%"  border="0" align="center" cellpadding="4" cellspacing="0">
        <tr bgcolor="#CCCCCC">
          <td width="58%"><strong>Student</strong></td>
          <td width="14%"><strong>Present</strong></td>
          <td width="14%"><strong>Absent</strong></td>
          <td width="14%"><strong>Late</strong></td>
        </tr>
    	<%
    	While Not rs.EOF
        	Response.Write("<tr>")
          	Response.Write("<td>" & rs("Name") & "</td>")
          	Response.Write("<td><input type=radio name=""status_" & rs("studentID") & """ value=""P""" & currentstatus("P") & "></td>")
          	Response.Write("<td><input type=radio name=""status_" & rs("studentID") & """ value=""A""" & currentstatus("A") & "></td>")
          	Response.Write("<td><input type=radio name=""status_" & rs("studentID") & """ value=""L""" & currentstatus("L") & "></td>")
        	Response.Write("</tr>")
    		rs.MoveNext
    	Wend
    	rs.Close
    	set conn = Nothing
    	%>

    My attempt at converting to Jscript
    -------------------------------------------------------

    Code:
    <%
    var conn, rs, strSQL
    conn = new ActiveXObject("ADODB.Connection");
    conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE =  " + Server.MapPath("db1.mdb"));
    if(Request.Form("update") == "update"){
     for each fld in Request.Form;
      if(Left(fld,7) == "status_"){
       student_id = CLng(Mid(fld,8));
       attendance = Request.Form(fld);
       strSQL = "Update tblattendatt_status = '" + attendance + "' WHERE studentID = " + student_id + " && att_date = Date()";
       conn.Execute strSQL, recsupdated ;
       if(recsupdated == 0){
        conn.Execute "Insert INTO tblattend(studentID,att_status,att_date) VALUES(" + student_id + ",'" + attendance + "', #"  + Month(Date()) + "/" + Day(Date()) + "/" + Year(Date()) + "#)";
       }
      }
     Next;
    }
     
    rs = conn.Execute("Select tblstudent.*, tblattend.att_status From tblstudent LEFT JOIN tblattend ON (tblstudent.studentID = tblattend.studentID && tblattend.att_date = Date()) ORDER by tblstudent.Name")
    
    function currentstatus(statval){
     if(rs("att_status") == statval){
      currentstatus = "checked";
     }else{
      currentstatus = "";
     }
     }
    %>
    <div align="center"><strong><font size="3">Attendance records for today</font></strong></div>;
    <form name="form1" method="post" action="">;
      <table width="50%"  border="0" align="center" cellpadding="4" cellspacing="0">;
        <tr bgcolor="#CCCCCC">;
          <td width="58%"><strong>Student</strong></td>;
          <td width="14%"><strong>Present</strong></td>;
          <td width="14%"><strong>Absent</strong></td>;
          <td width="14%"><strong>Late</strong></td>;
        </tr>;
     <%;
     While ! rs.EOF;
         Response.Write("<tr>");
           Response.Write("<td>" + rs("Name") + "</td>");
           Response.Write("<td><input type=radio name=""status_" + rs("studentID") + """ value=""P""" + currentstatus("P") + "></td>");
           Response.Write("<td><input type=radio name=""status_" + rs("studentID") + """ value=""A""" + currentstatus("A") + "></td>");
           Response.Write("<td><input type=radio name=""status_" + rs("studentID") + """ value=""L""" + currentstatus("L") + "></td>");
         Response.Write("</tr>");
      rs.MoveNext;
     Wend;
     rs.Close;
    conn = null;
     %>

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    You have a misplaced semi-colon in there. Also, the For Each loop is syntatically different in JScript.

    It should be:
    Code:
    for (var fld in Request.Form)
    {
       ...
    }
    It may print unexpected data, however. See this article: http://blogs.msdn.com/ericlippert/ar.../22/53063.aspx

    Regards.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles