|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Classic ASP Listbox selection enables textbox
I need to use the selection of a Listbox that ASP generates from a table to enable or disable a textbox, without first updating the database with the selection. I have a JavaScript function that will do the Enable/Disable portion of the job, it works great. The onClick to call the function works great. I cannot access the selected value for the IF ELSE statement.
The ASP looks like this: <% Dim lbStatus Set lbStatus = new ListBox lbStatus.dataSource = oConn.Execute("SELECT Status FROM MRCStatus") lbStatus.name = "lbStatus" lbStatus.valueField = "Status" lbStatus.displayField = "Status" 'lbStatus.addItem "1-New", "1-New" 'make New the default lbStatus.style = "font-family: 'courier new'; font-size: 9pt;" lbStatus.selectedValue = rsRequest.Fields("Status") lbStatus.display() Set lbStatus = Nothing %> Our first try was: var status=document.thisForm.lbStatus.options[document.thisForm.lbStatus.selectedIndex] Any suggestions greatly appreciated! |
|
#2
|
|||
|
|||
|
Solved
// status returns the position numbers 0-3
var status=document.thisForm.lbStatus.selectedIndex // 4-Deleted is in position 3 if(status==3) { Just eliminated the attempt to turn the position marker into the text value and it works. |
|
#3
|
||||
|
||||
|
Quote:
--> Moved to javascript Forum Glad you solved your problem, but I just wanted to point out that you may encounter problems if your options were to change order for some reason. You may be best testing for the value that is actually displayed to the user instead of the position of the option, try this: Code:
var status=document.thisForm.lbStatus[document.thisForm.lbStatus.selectedIndex].value; |
|
#4
|
|||
|
|||
|
Quote:
Discovered that one after the fact this morning. Now I'm working a new problem. I need to disable the ability of some users to change the value of the listbox, but not disable the listbox because that returns a null to the database. Readonly hasn't been working so far, but I've barely started. |
|
#5
|
||||
|
||||
|
One option would be to just display the value on the screen if they don't have the correct access, you could include a hidden form element that contains your value so it would still be inserted into the database, eg:
Code:
<%
Dim rs, sql
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT is_authorised FROM auth_users WHERE user_name = " & strUserName
Set rs = oConn.Execute(sql)
If rs.EOF <> True Then
'User exists in auth_users table, show the list box
Dim lbStatus
Set lbStatus = new ListBox
lbStatus.dataSource = oConn.Execute("SELECT Status FROM MRCStatus")
lbStatus.name = "lbStatus"
lbStatus.valueField = "Status"
lbStatus.displayField = "Status"
'lbStatus.addItem "1-New", "1-New" 'make New the default
lbStatus.style = "font-family: 'courier new'; font-size: 9pt;"
lbStatus.selectedValue = rsRequest.Fields("Status")
lbStatus.display()
Set lbStatus = Nothing
Else
'Not authorised, display value on screen and create hidden textbox containing value
Response.Write(rsRequest.Fields("Status"))
Response.Write("<input type=""hidden"" name=""lbStatus"" value="" & rsRequest.Fields("Status") & """)
End If
%>
|
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Classic ASP Listbox selection enables textbox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|