Scripting Help Needed - Working with Function and OnBlur 
Author Message
 Scripting Help Needed - Working with Function and OnBlur

Hello.

I need help.  I should note that I've also posted this message to the
macromedia.ultradev group, but not heard anything.  I am working with
UltraDev, developing ASP with VBScript.

I have been trying to write what seems to be a fairly
simple function and getting error messages for lines that are not part
of what I'm writing. Bascially, I want to check the date entered to
make sure it is not for more than 30 days prior to the current date.
I have this happening on the OnBlur event of the date field.

Actually, the errors are happening to code generated by Ultra Dev to
write the sql insert statement.  (Full code at end of message)

This is the line:  If (AltVal <> "") Then

I get an error message saying Object Required.

Any help would be VERY much appreciated.  I've been trying to do this
for DAYS...

TIA

-- Kim

Here is all of the code for the page:

<%
' *** Logout the current user.
MM_Logout = CStr(Request.ServerVariables("URL")) & "?MM_Logoutnow=1"
If (CStr(Request("MM_Logoutnow")) = "1") Then
  Session.Abandon
  MM_logoutRedirectPage = "Login.asp"
  ' redirect with URL parameters (remove the "MM_Logoutnow" query
param).
  if (MM_logoutRedirectPage = "") Then MM_logoutRedirectPage =
CStr(Request.ServerVariables("URL"))
  If (InStr(1, UC_redirectPage, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
    MM_newQS = "?"
    For Each Item In Request.QueryString
      If (Item <> "MM_Logoutnow") Then
        If (Len(MM_newQS) > 1) Then MM_newQS = MM_newQS & "&"
        MM_newQS = MM_newQS & Item & "=" &
Server.URLencode(Request.QueryString(Item))
      End If
    Next
    if (Len(MM_newQS) > 1) Then MM_logoutRedirectPage =
MM_logoutRedirectPage & MM_newQS
  End If
  Response.Redirect(MM_logoutRedirectPage)
End If
%>
<!--#include file="Connections/FUNDdb.asp" -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

  MM_editConnection = MM_FUNDdb_STRING
  MM_editTable = "tblHourlyTracking"
  MM_editRedirectUrl = "projectlist.asp"
  MM_fieldsStr  = "BillDate|value|ConsultantNo|value|ProjectNo|value|Description|value|Comments|value|LogHours|value|Maintenance|value|Proposal|value"
  MM_columnsStr = "BillDate|',none,NULL|ConsultantNo|none,none,NULL|ProjectNo|none,none,NULL|Description|',none,''|Comments|',none,''|LogHours|none,none,NULL|Maintenance|none,-1,0|Proposal|none,-1,0"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")

  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" &
Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" &
Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues
& ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim rsProjectName__MMColParam
rsProjectName__MMColParam = "1"
if (Request.QueryString("ProjectNo") <> "") then
rsProjectName__MMColParam = Request.QueryString("ProjectNo")
%>
<%
set rsProjectName = Server.CreateObject("ADODB.Recordset")
rsProjectName.ActiveConnection = MM_FUNDdb_STRING
rsProjectName.Source = "SELECT * FROM qryProjectName WHERE ProjectNo =
" + Replace(rsProjectName__MMColParam, "'", "''") + ""
rsProjectName.CursorType = 0
rsProjectName.CursorLocation = 2
rsProjectName.LockType = 3
rsProjectName.Open()
rsProjectName_numRows = 0
%>
<%
Dim rsConsultantName__MMColParam
rsConsultantName__MMColParam = "1"
if (Session("ConsultantNo") <> "") then rsConsultantName__MMColParam =
Session("ConsultantNo")
%>
<%
set rsConsultantName = Server.CreateObject("ADODB.Recordset")
rsConsultantName.ActiveConnection = MM_FUNDdb_STRING
rsConsultantName.Source = "SELECT * FROM qryConsultantName WHERE
ConsultantNo = " + Replace(rsConsultantName__MMColParam, "'", "''") +
""
rsConsultantName.CursorType = 0
rsConsultantName.CursorLocation = 2
rsConsultantName.LockType = 3
rsConsultantName.Open()
rsConsultantName_numRows = 0
%>
<%
Function ValiDate()
        Dim varToday
        Dim varEarliestDay
        Dim varBillDay
        varToday = Date()
        varEarliestDay = varToday - 30
        varBillDay = Request("BillDate")
        If varBillDay <= varEarliestDay Then
                ErrorMsg = "You can not log hours for work that was done more than
30 days ago."
        End If
End Function
%>
<html>
<head>
<title>NCA Database - Log Hours</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script language="JavaScript">
<!--

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;

Quote:
}

function YY_checkform() { //v4.07
//copyright (c)1998,2001 Yaromat.com
  var args = YY_checkform.arguments,myDot=true,myV='',myErr='',addErr=false,myReq,rx,myObj1,myMa,myAt;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true;
args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'){
      if (myReq&&myObj.value.length==0)addErr=true;
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        if (!(myV/1)||myV<args[i+1].split('_')[0]/1||myV >
args[i+1].split('_')[1]/1){addErr=true}
      }
      if ((myV.length>0)&&(args[i+2]==2)){ // email
;
          }
      if ((myV.length>0)&&(args[i+2]==3)){ // date
        myMa=args[i+1].split("#");myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var
myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      }
      if ((myV.length>0)&&(args[i+2]==4)){myMa=args[i+1].split("#");myAt=myV.match(myMa[0]);if(!myAt)addErr=true}//
time
      if (myV.length>0&&args[i+2]==5){ // check this 2
        var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
        if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
        if(!myObj1.checked)addErr=true;
      }
      if (myV.length>0&&args[i+2]==6){myObj1=MM_findObj(args[i+1]);if(myV!=myObj1.value)addErr=true;}//
the same
    }else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    }else
    if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    }else
    if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else
    if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    } if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is
incomplete:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
Quote:
}

//-->
</script>

<%Function ValiDate()%>
        <%Dim varToday%>
        <%Dim varEarliestDay%>
        <%Dim varBillDay%>
        <%varToday = Date()%>
        <%varEarliestDay = (varToday - 30)%>
        <%varBillDay = Request("BillDate")%>
        <%If varBillDay <= varEarliestDay Then%>
                <%ErrorMsg = "You can not log hours for
...

read more »



Sat, 26 Jun 2004 21:12:01 GMT  
 Scripting Help Needed - Working with Function and OnBlur
"Kim Snyder" wrote ...

Quote:
> Here is all of the code for the page:

Try reposting your message with the code attached in a separate ASP page. I
tried to run it but I got many syntax errors from lines that seemed out of
context with the rest of the script. I think your news client is wrapping
the lines before sending at a length shorter than the pages's script.

Regards,

Fred Chateau



Sat, 26 Jun 2004 23:36:23 GMT  
 Scripting Help Needed - Working with Function and OnBlur
Hello.

Thanks for your reply.  Actually, when all was said and done, I very
systematically worked through this coding, the script, the references,
etc. and finally got it to work!!!  Often I'm too impatient, but the
slow, incremental method works best.

It did not end up being OnBlur, but rather the OnClick of the next field
(for some reason OnBlur didn't do anything).  I ended up inserting
script incorporating the DateDiff function and it worked.

As I suspected, it was actually a very simple little bit of code...
<script language = vbscript>
sub Description_onClick

        Dim vDateNow
        Dim vDateLog
        Dim vDateBetween

        vDateNow = Date()
        vDateLog = Form1.BillDate.value
        vDateBetween = DateDiff("d", vDateNow, vDateLog)

        if vDateBetween <= -30 then
        msgBox "You can not log activities that happened more than 30 days
ago."
        end if

End sub
</script>

Thanks.

-- Kim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 27 Jun 2004 00:21:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Needs help on the FileCopy function in Scripting.FileSystemObject

2. Help needed getting the ChooseFont api function to work

3. window.close works too well onblur !!

4. onBlur not work

5. Script works, script don't work

6. help, this javascript function works with IE but not Netscape

7. tiny text scroll function not working, please help

8. network functions don't work in login scripts in 95

9. Help with ONBLUR please?

10. Need Help to get code to work in Netscape

11. Help needed !! Why doesn't this work

12. need help ps2ascii not work

 

 
Powered by phpBB® Forum Software