SunQuest
           ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

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 Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old July 10th, 2003, 09:05 PM
tp194 tp194 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 8 tp194 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Form drop down boxs and ASP

Hi

I have a form with two drop down boxes next to each other.

In Javascript you can use document.option[int].selected, to test if the user has made a selection, usually if the selection is [0], then the user has not made a selection...

Is there a way to achieve this using ASP?

My problem is the user can only select from one of the drop down menus. If they choose the first one and submit the form, it runs one sql statement, if they choose from the second menu, it runs another statement.

I'm using an if-then-else statment in ASP, but I don't know how to check the array elements from the drop down box...the code is below. (As you can see, I tried to use Count, but it didn't work)

Thanks

Terry

<%
Dim objCommand, objCommand2, selectedGroup, objRS


Response.Write Request.Form("staff").Count & "This is count"



If Request.Form("commodity").options[0].selected Then



Set objCommand = Server.CreateObject("ADODB.Command")



objCommand.ActiveConnection = strConnect



objCommand.CommandText = "SELECT buyerTable.buyerName, buyerTable.phone, buyerTable.email, buyerTable.title, commodityCodeList.description, buyerTable.fax " & _

"FROM buyerTable INNER JOIN " & _

"(linkToBuyerTable INNER JOIN " & _

"commodityCodeList " & _

"ON (linkToBuyerTable.categoryId = commodityCodeList.categoryId)) " & _

"ON (buyerTable.buyerInitials = linkToBuyerTable.buyerInitials) " & _

"WHERE commodityCodeList.categoryId = " & commodity & " " & _

"ORDER BY buyerTable.hierarchy"



objCommand.CommandType = adCmdText



'objCommand.Parameters("commodity") = commodity



Set objRS = objCommand.Execute





Response.Write "<body><p><img src="

Response.Write "images/banner.gif>"

Response.Write "</p><hr>"



Response.Write "<p>You searched for Commodity Code <em>" & objRS("description") &"</em></p>"

Response.Write "<p>For more information, or help procuring any goods or services related to <em>" & objRS("description") & " </em>please contact any one of the following names listed below</p>"



While Not objRS.EOF



Response.Write "<div>" & objRS("buyerName") & "</div>"

Response.Write objRS("title") & "<br>"

Response.Write objRS("phone") & " (p)<br>"

Response.Write objRS("fax") & " (f)<br>"

Response.Write "<a href=mailto:" & objRS("email") & ">" & objRS("email") & "</a></p>"



objRS.MoveNext

Wend


Set objCommand = Nothing
Else



Set objCommand2 = Server.CreateObject("ADODB.Command")



objCommand2.ActiveConnection = strConnect



objCommand2.CommandText = "SELECT buyerTable.buyerName, buyerTable.phone, buyerTable.email, buyerTable.title, commodityCodeList.description, buyerTable.fax " & _

"FROM buyerTable INNER JOIN " & _

"(linkToBuyerTable INNER JOIN " & _

"commodityCodeList " & _

"ON (linkToBuyerTable.categoryId = commodityCodeList.categoryId)) " & _

"ON (buyerTable.buyerInitials = linkToBuyerTable.buyerInitials) " & _

"WHERE buyerTable.buyerInitials = staff " & _

"ORDER BY commodityCodeList.description"



objCommand2.CommandType = adCmdText



objCommand2.Parameters("staff") = staff



Set objRS = objCommand2.Execute



Response.Write "<body><p><img src="

Response.Write "images/banner.gif>"

Response.Write "</p><hr>"



Response.Write "<p>You searched for Commodity Codes that <em>" & objRS("buyerName") &"</em> handles</p>"

'Response.Write "<p>For more information, or help procuring any goods or services related to any of these commodities, please contact <em>" & objRS("staff") & " </em></p>"





Response.Write "<div>" & objRS("buyerName") & "</div>"

Response.Write objRS("title") & "<br>"

Response.Write objRS("phone") & " (p)<br>"

Response.Write objRS("fax") & " (f)<br>"

Response.Write "<a href=mailto:" & objRS("email") & ">" & objRS("email") & "</a></p>"



While Not objRS.EOF

Response.Write "<div>" & objRS("description") & "</div>"

objRS.MoveNext

Wend

Set objCommand = Nothing

End If

%>

Reply With Quote
  #2  
Old July 11th, 2003, 02:10 AM
OldJacques's Avatar
OldJacques OldJacques is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: in Orbit mostly
Posts: 148 OldJacques User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Server side vs. Client side

The problem is your mixing up a Server side technology (ASP) with a Client side technology (Javascript).
Request.Form("commodity").options[0].selected doesn't exist, because by the time the form is submitted to the ASP Script for evaluation, you don't have a Form anymore, just the selected results.
If you were to add an:
Response.Write "<br />commodity is::" & Request.Form("commodity") & "::<br />" & VbCrLf
you should see any selected value already.
Your script needs to take this into consideration, and deal with the selected value which is the only one passed to the ASP script by the form.
The Request.Form.Count should return the total number of values passed in the field to the script using the POST method, in the case of multiple values (a Multiple Select Control or Multiple Checkboxes with the same name). You still need to loop through the array to do something with the (multiple) values contained there

Reply With Quote
  #3  
Old July 11th, 2003, 03:15 PM
tp194 tp194 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 8 tp194 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks...I was able to solve the problem by using:

If Request.Form("commodity") > 0 Then

Because the first element in the drop down box is at position 0, this way I can test to see if a user has selected anything from that box based on the element number...does this make sense?

In any event, it works...so thanks for your reposnse!

t~

Reply With Quote
  #4  
Old July 11th, 2003, 03:36 PM
OldJacques's Avatar
OldJacques OldJacques is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: in Orbit mostly
Posts: 148 OldJacques User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Exclamation Watch out!

Quote:
Originally posted by tp194
Thanks...I was able to solve the problem by using:
If Request.Form("commodity") > 0 Then
Because the first element in the drop down box is at position 0, this way I can test to see if a user has selected anything from that box based on the element number...does this make sense?
In any event, it works...so thanks for your reposnse!
t~

No it doesn't, and you're making a programming error, unless the value associated with each of the options in the select control is the number (kinda' unusual if it is...).
The position has NO relationship to the value once it is passed to the eveluating ASP page, and probably never did have any relationship to the value.
You are still mixing up client-side and server-side.
Sort of like saying the brakes are fine because you keep slowing down while going up the mountain...just don't start back down unless your sure it was really the brakes slowing you...
If, on the other hand, it is the text value, you are basing it on a false comparison which in this case is taking advantage of the weak typing in PHP.
What you need to do is check that it is not an empty string, and assure that the first option HAS the value of an empty string.
<select name="commodity">
<option value="" selected>Select a commodity</option>
<option value="whatever">whatever</option>
<option value="else">else</option>
<option value="another">another</option>
</select>
The position (taken from the document.option[int].selected you keep insisting on citing CLIENT-Side) doesn't come into play, unless you have set it up as:
<select name="commodity">
<option value="0" selected>Select a commodity</option>
<option value="1">whatever</option>
<option value="2">else something more</option>
<option value="3">another thingy</option>
</select>
Beware, you are running down the hill and I don't think your brakes will last...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > RE: Form drop down boxs and ASP


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway