Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does Listbox Exist 1

Status
Not open for further replies.

mts176

MIS
Apr 17, 2001
109
US
I am currently working on a page that before save displays a dropdown listbox. Once the page is saved the list box is replaced with uneditable text. When I run the page after the save I get an error relating to the listbox, that is no longer created.

Is there a way for me to check to see if the listbox exists, created, etc.. on page load, so that it doesn't run through code to use the listbox.

I thought there was an exist function for items such as listboxes. The only exist I can find is for filesystem.objects.

Once again any help is appreciated.
 
Do you have any relevant code to show that might offer an idea of what is happening?

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
This is the code that I am using and the listbox that is giving me trouble.

This selection made with this list box is used to create a folder and excel file, so after it is selected we can not change the Project number. "PassType" is set to true after the user submits the page the first time.

<TD align=center>
<%If PassType = "edit" then
sql = "SELECT Project_ID, Code "
sql = sql & "FROM tblProjectCodes "
sql = sql & "WHERE Project_ID = " & ProjID & " "
Set rs = conn.Execute(sql)
Response.Write "<!--"&sql&"-->"
'Response.End
If not rs.eof then
xprojcode = rs("Code")
Response.write rs("Code")
End If
set rs = Nothing
Else%>
<SELECT name=lstCURRENT>
<OPTION VALUE=0 selected> Project No. </OPTION>
<%
' Format SQL to get current project info
sql = "SELECT PC.Project_ID, PC.Code, PC.Description, CU.Cust_Name_Short "
sql = sql & "FROM tblProjectCodes PC, tblCustomer CU "
sql = sql & "WHERE PC.Active_Flag = 1 AND PC.Cust_ID = CU.Cust_ID "
sql = sql & "ORDER BY ProjOrder"
IF Session("Debug") Then
Response.Write "<!-- " & sql & " -->"
End IF
Set rs = conn.Execute(sql)
Do While Not rs.eof
If IsNumeric(Session("INVProjID")) Then
If Clng(rs("Project_ID")) = Clng(ProjID) Then
%><OPTION value="<%= rs("Project_ID") %>" selected><%= rs("Code") %></OPTION><%
Else
%><OPTION value="<%= rs("Project_ID") %>"><%= rs("Code") %></OPTION><%
End If
Else
%><OPTION value="<%= rs("Project_ID") %>"><%= rs("Code") %></OPTION><%
End If
rs.movenext
Loop
set rs = Nothing
%>
</SELECT><%
End If
%><Input type=hidden name=xprjCode value="<%=xprojcode%>">
<input type=hidden name=ProjID value=<%=ProjID%>>
</TD>
 
Instead of checking to see if the listbox exists, maybe check to see if some type of save variable is set. Another option might be to make the listbox invisible instead of removing it completely. Some code would help though to what would work.
 
The <Script language=vbscript> tags make calls to the list box.

Such as:

iIndex = document.fme.lstCURRENT.selectedIndex
prjcode = document.fme.lstCURRENT.options(document.fme.lstCURRENT.selectedIndex).text
document.fme.xprjCode.value = document.fme.lstCURRENT.options(document.fme.lstCURRENT.selectedIndex).text
 
In javascript, you could use something akin to the following:
Code:
if(document.fme.lstCURRENT) {
 //do something here
}
I'm sure that the process would be similar for vbscript. You just check to ensure that the object exists on the page before you attempt to refer to it.

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Im still getting the error:

Object doesn't support this property or method:

document.fme.lstCURRENT
Code:0

I am trying to trap the error but I cant do that either.


iIndex = document.fme.lstCURRENT.options(document.fme.lstCURRENT.selectedIndex).value
prjcode = document.fme.lstCURRENT.options(document.fme.lstCURRENT.selectedIndex).text
On Error Resume Next
IF err.number THEN
szMsg = "The following error occurred: {" & err.number & "} " & vbCrLf & vbLf & err.description & vbCrLf & vbLf
szMsg = szMsg & "Source: " & err.source
MsgBox szMsg, vbApplicationModal + vbExclamation + vbOKOnly, "Delete File Error"
End If
 
It fails because it is not an object. You first need to verify whether the object exists. In vbscript, I think there is a built-in function called IsObject. So encapsulate your existing code with that:
Code:
[COLOR=red]if isObject(document.fme.lstCURRENT) then[/color]
  iIndex = document.fme.lstCURRENT.options(document.fme.lstCURRENT.selectedIndex).value
  prjcode = document.fme.lstCURRENT.options(document.fme.lstCURRENT.selectedIndex).text
[COLOR=red]end if[/color]

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Im sorry Chopstik I get the same error, but now it is on the opening if statement. I might have to take the long way around this. Thanks for the help.
 
I tried monkeying around with it in VBScript but was unable to find a satisfactory answer. I do know that the javascript solution I provided to you earlier will work, though. Not sure if you are prevented from using it for other reasons, but it is a potential alternative. Sorry I couldn't be of more assistance.

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Another potential workaround (though I personally don't like it) might be to create a hidden variable with the same name. This way, you would still be able to reference it and run from there.

That, or you could create a separate variable when you post your request page and then, based on whether it is populated or not, modify your vbscript function that resets the values to include/not include the missing object.

Both are (ugly) workarounds, I know, but may be other alternatives...

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Your last post is my "long way" around. I was hoping for something clean and fast, but I guess slow and dirty is the only way left.

I could use Javascript on the page, but recently we have been having trouble with pages that mix Java and VB. Not sure why, but one day it breaks, the next it works fine. Personally I believe they are user errors (just because I can't recreate them), but my fellow emps claim no responsibility. Someone in power, that just learned to spell HTML, discovered that the pages that "broke" have both Java and VB on them, so now it is VB all the way.

Thank you for your help.

 
Just a final thought about using VBscript and Javascript on the same page - DON'T. As you have noticed, they do not work together and you get random errors. Use either or.

But if you're coding for internet, then it might be better to use javascript since VBScript is only supported by IE. Just my two cents, mind you...

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top