So I have the following code on my asp page that should hide/unhide a textbox depending on the two conditions and whether or not they are both met.
if request.form("Requester_Presenter") = 1 and request.form("Additional_Presenters") = 0 then
ErrorMessage = ErrorMessage + "<dd>- If you are not a presenter, there must be additional presenters selected so you can provide their contact information in the next step.</dd>"
document.form.presenters.style.display = "none"
end if
if request.form("Requester_Presenter") = 0 and request.form("Addition_Presenters") = 0 then'do something'
document.form.presenters.style.display = "block"
end if
when I run my code however, I get the following error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'document'
which says that I am experiencing my error on the line where I set the textbox to display: none; or display:block;
What am I doing wrong here?
Classic ASP (vbScript) is a Server side scripting language and what you're trying to do is mix Server side code with client side code (document is available in javascript and represent the current loaded page in the DOM)
What you can do, is embed this code inside a script html tag and have it output some javascript :
<script type="text/javascript">
<%
if request.form("Requester_Presenter") = 1 and request.form("Additional_Presenters") = 0 then
ErrorMessage = ErrorMessage + "<dd>- If you are not a presenter, there must be additional presenters selected so you can provide their contact information in the next step.</dd>"
%>
document.form.presenters.style.display = "none"
<%
end if
if request.form("Requester_Presenter") = 0 and request.form("Addition_Presenters") = 0 then 'do something'
%>
document.form.presenters.style.display = "block"
<% end if %>
</script>
Related
Insert and resize a picture in an access report
Solution by Ms Isabel Smit aborts at first line of code.
My Report textbox [P1] populated by query has links to *.jpg files.
But code, Me.Image46.Picture = Me.P1.Value does not work. Get error msg Run-time error '94': Invalid use of Null.
Neither does Me!Image46.Picture = Me![P1] Run-time error '13': Type mismatch
Neither does Me!Image46.Picture = Me![P1].Value
Works if Me!Image46.Picture = hard coded filename but it defeats objective of each record to link to different filename.
Thank you
Updated Solution with validation:
I built your form and tested it. The only time I got it to fail was when the path to the image was invalid. Please try this:
Dim strFilename As String
strFilename = Me![P1].Value
If Len(Dir(strFilename)) > 0 Then
Me![Image7].Picture = strFilename
Me![Image7].Height = 9666 * Me![Image7].ImageHeight / Me![Image7].ImageWidth
Me![Image7].Width = 9666
Else
MsgBox "Image not found"
End If
Connection file
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "abc","ID","Password"
conn.commandtimeout=120
Set RS = Server.CreateObject("ADODB.RecordSet")
rs.activeConnection = Conn
%>
Classic ASP file
<%response.buffer = true%>
<%Response.Expires = 0%>
<!-- #include file="functions.asp" -->
<% Response.Write session("RequestID")%>
<%if session("ValidLogon") <> "true" then
if request("FromEmail") = "True" then
SetSessVar()
else%>
<%response.redirect "Default.asp"
end if
end if%>
<html>
<body>
<%rs.Source = "SELECT * from tblRequests WHERE RequestID = " & request("requestID")
rs.Open
session("RequestID") = rs("requestid")
if rs("RequestType") = "O" then
response.clear
If request("Tag") = "Change" then
response.redirect "abc.asp#change"
else
response.redirect "abc.asp?From=" & request("From")
end if
else
response.clear
If request("Tag") = "Change" then
response.redirect "editinternal.asp#change"
else
response.redirect "editinternal.asp?From=" & request("From")
end if
end if
rs.close%>
</body>
</html>
I have checked the classic asp page and it looks like there is an error in syntax inside "Body" tag. I don't know anything about it.
It is giving internal server error 500.
In Connection File you are missing Set on rs.activeConnection = Conn as you are setting an object reference to the ADODB.Connection object instance not passing a connection string.
'Object instances require Set
Set rs.activeConnection = Conn
Please make sure that you configure your site to send the detailed error messages to the client
This describes how:
Show detailed errors
I would guess that your connection "abc"/"ID"/"Password" has to be a real connection. It seems that you just wrote something to see what happens. It could also be the "functions.asp" file that you are including. Does that file exist, what does it contain?
Please post back your detailed error messages, then we can help you better.
Before referencing to the recordset you should check if the recordset contains any records like:
If not rs.eof then
Session("reqestid") = rs("reqestid")
....
End If
Just want to add one trix here, try add these 2 lines right after the body tag
Response.Write "<br>For the sake of debug"
Response.Flush
If you have buffering on, this sometimes writes out the error instead of throwing out error 500. Helps me often.
I want to use VBScript to click a button that reads “Add Document” in the GUI of an application that runs in Internet Explorer. The problem is there is no “id”, “name” , or “class” element in the source code (see below) to use as a reference in the script.
Source Code:
<TD>
<INPUT type="button" value="Add Document" onclick="addFileUploadBox()">
</TD>
My code is below and works for elements that have source code ids. Also included are some failed attempts to click the button in question based on my googling but I cant get to work. I'm new to this and any help would be appreciated - any suggestions to fix?
My Code:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://sharemxxxx.xxxxx.com/xxxImport/import.aspx"
While objIE.Busy
WScript.Sleep 100
Wend
objIE.Document.getElementById("txtReferenceNum").value = "15226002"
objIE.Document.getElementById("ddlCategory").value = "05"
objIE.Document.getElementById("btnRetrieve").click
' ABOVE CODE WORKS
' NOT WORKING #1 - DOES NOTHING - NO ERROR
'===========================================
objIE.Document.getElementByType("btn").Value="Add Document"
For Each btn In objIE.Document.getElementsByTagName("input")
If btn.Value="Add Document"Then btn.Click()
Next
' NOT WORKING #2 - DOES NOTHING - NO ERROR
'===========================================
For Each Button In objIE.Document.getElementsByTagName("input")
If Button.Value="Add Document"Then Button.Click()
Next
' NOT WORKING #3 - DOES NOTHING - NO ERROR
'===========================================
Set oInputs = objIE.Document.getElementsByTagName("input")
For Each elm In oInputs
If elm.Value = "Add Document" Then
elm.Click
Exit For
End If
Next
' NOT WORKING #4 - Show Empty Msg Box
'===========================================
set objButtons = objIE.document.getElementsByTagName("input")
for each objButton in objButtons
strText = objButton.innerhtml
msgbox strText
if (strText = "Add Document") then
msgbox "found the button!"
objButton.click
exit for
end if
next
You probably don't even need to find the element. It looks like the button just calls a JavaScript function. So you can use the execScript() function to run it.
For example:
objIE.Document.parentWindow.execScript "addFileUploadBox();", "javascript"
I have a file header.asp that has an server side include head.asp. Inside head.asp my connection to my database is created and is accessible from the header.asp file and pages that use the header.asp file as an server side include (in this case my core.asp file). Inside core.asp I have the following:
if request.querystring("page") = "" then
response.write("<p>No data to load</p>")
else
page = request.querystring("page")
set fso = createobject("scripting.filesystemobject")
FileName = "../Pages/" & page & ".asp"
if fso.FileExists (server.mappath(FileName)) then
Server.Execute(FileName)
else
response.write("<p>Could not validate page. Try again.</p>")
end if
end if
This executes just fine and the proper page renders inside the core.asp file. My issue, is that the connection string (from head.asp) is not available to the file being called from Server.Execute. Thus, I cannot run database queries, etc. on this page unless I were to instantiate the object anew. Is there any way to use the object created?
If I have not explained this properly, I will expound as I am able given my intermediate experience level.
As a follow up to answer #1, if I've followed the logic correctly, I'm attempting to create the connection object at the application level (global.asa):
Sub Application_OnStart()
dim oConn, connectstr
set oConn = Server.CreateObject("ADODB.Connection")
connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=theServer; DATABASE=theDatabase; UID=theUserID; PWD=thePassword"
oConn.ConnectionTimeout = 5
oConn.Open connectstr
Application("con") = oConn
end Sub
</script>
Attempting to access the object like so from my page that includes the global.asa as an IIS:
qryAdmin = "select * from table"
set rsAdmin = Application("con").execute(qryAdmin)
The results are the same. I receive the "Object required" error. Any glaring errors that could be causing this?
Assign this object to a session variable and you can access it from any page you like...
Session("MyConnectionObj")= CONN
CONN is your instantiated connection object on the page where you instantiate your connection originally. And in your executed file just call
set NewCONN=Session("MyConnectionObj")
RS.Open strSql ,NewCONN,1,1
where strSql is your SQL, RS is your recordset etc... Obviously if you calling the stored procedure, it will look slightly different but you get the point.
Edited to show that object have to be declared and set before one using it. As I see at least one "expert" did not know that.
Edited base on comments from Window Frog:
did you try it like that:
<%
if request.querystring("page") = "" then
response.write("<p>No data to load</p>")
else
page = request.querystring("page")
set fso = createobject("scripting.filesystemobject")
FileName = "../Pages/" & page & ".asp"
if fso.FileExists (server.mappath(FileName)) then%>
<!--#include file="<%=FileName %>" -->
<% else
response.write("<p>Could not validate page. Try again.</p>")
end if
end if
%>
I am trying to click a link on a page, it don't have any id and not having a unique class name. Only unique thing about the function is the onclick handler
<a href="#" onclick="closepopup('popup', 'popuphandler')" > </a>
I need to click this link via vbscript automation, for the same i tried the code as:
Set allLinks = ie.document.links
for j = 0 to allLinks.length-1
if allLinks(j).onClick = "closePopup(""popup"",""popupClose"")" then
allLinks(j).click
j = allLinks.length 'class name = blueButtonCenter
end if
Next
But it is not working, please help.
Thanks in advance :)
You didn't specify what doens't work, finding the link or clicking it, in the first case:
onClick wil return something like
about:blank# function onclick()
{
closepopup('popup', 'popuphandler')
}
so you shoudl use instr to check if it is the right link
Dim HTMLDoc, XML, URL, table
Set HTMLDoc = CreateObject("HTMLFile")
Set XML = CreateObject("MSXML2.XMLHTTP")
URL = "your url"
With XML
.Open "GET", URL, False
.Send
HTMLDoc.Write .responseText
End With
Set allLinks = HTMLDoc.links
For each link in allLinks
if instr(link.onClick, "closepopup('popup', 'popuphandler')") then
link.click
exit for
end if
Next
Only the click won't work this way..
I would try to check if the closePupup is found in the actual javascript, like so:
'safety first
if not isnull(allLinks(j).onClick) then
if instr(allLinks(j).onClick.toString() , "closePopup(""popup"",""popupClose"")" ) > -1 then
allLinks(j).click
j = allLinks.length 'class name = blueButtonCenter
end if
end if
This assumens onClick delivers a string, (at least in javascript it does and in IE9 and Chrome this works)