HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 20th, 2009, 12:03 PM
tpickard tpickard is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 5 tpickard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 26 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old August 20th, 2009, 03:49 PM
tpickard tpickard is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 5 tpickard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 26 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old August 24th, 2009, 05:59 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
Quote:
Originally Posted by tpickard
// 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.

--> 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;

Reply With Quote
  #4  
Old August 24th, 2009, 02:27 PM
tpickard tpickard is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 5 tpickard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 26 sec
Reputation Power: 0
Quote:
Originally Posted by sync_or_swim
--> 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;


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.

Reply With Quote
  #5  
Old August 25th, 2009, 06:10 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
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
%>

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Classic ASP Listbox selection enables textbox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek