Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2003, 05:29 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help with IF in HTML/ASP

I have designed a webpage using FORM to print out all fields in a table fra my Access database. I need to manipulate the HTML code according to the value of certain fields in my table, ie. I have an Option-box which contains 3 values. If value1 then display a new fieldA, if value2 then display a new fieldB, if value3 then I don't need to dislay any new fields. As you can see I need the IF .. THEN procedure to be mutually exclusive, but I haven't managed to do this.
Here's an example of my code:
(Lets assume that the "Ownership" field below is a select option-box with 3 different values: own, rent, free)

<TR>
 <TD>Ownership: </TD>
 <TD>
  <INPUT TYPE="Text"
   NAME="payment"
   VALUE="<% Response.Write Rs1("[ownership]") >"
   SIZE="20">
 </TD>
</TR>

<%
  If Rs1("[ownership]") = "Own" Then ... [Print out "Cost:" field below]
  If Rs1("[ownership]") = "Rent" Then ... [Print out "Owners name:" field below]
  If Rs1("[ownership]") = "Free" Then ... [Nothing]
%>

<TR>
 <TD>Cost: </TD>
 <TD>
  <INPUT TYPE="Text"
   NAME="cost"
   VALUE="<% Response.Write Rs1("[cost]") %>"
   SIZE="20">
 </TD>
</TR>

<TR>
 <TD>Owners name: </TD>
 <TD>
  <INPUT TYPE="Text"
   NAME="owner"
   VALUE="<% Response.Write Rs1("[ownername]") %>"
   SIZE="20">
 </TD>
</TR>

How do I write my IF sentences so that this will work as I want it to.

Thanks for your help!

A. GRebstad
 
Old August 29th, 2003, 05:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
<% 
  Select Case UCase(Rs1("[ownership]"))
    Case "OWN"
%>

<TR>
 <TD>Cost: </TD>
 <TD>
  <INPUT TYPE="Text" 
   NAME="cost" 
   VALUE="<%=Rs1("[cost]") %>"
   SIZE="20">
 </TD>
</TR>  
<% Case "RENT" %>
<TR>
 <TD>Owners name: </TD>
 <TD>
  <INPUT TYPE="Text" 
   NAME="owner" 
   VALUE="<%=Rs1("[ownername]") %>"
   SIZE="20">
 </TD>
</TR>
<% Case Else
      ' do nothing
   End Select %>
 
Old August 29th, 2003, 06:04 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your code looks fine, but I get the following error:
---

Microsoft VBScript compilation error '800a0408'

Ugyldig tegn (translated to English: Illegal symbol?)

/test/database/updatetable.asp, line 148

 Case "OWN"
^

---

What could be wrong ?

Thanks for your help by the way!
 
Old August 29th, 2003, 06:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hmm interesting! There's nothing wrong with that syntax. Are you sure there's not some duff syntax just before it? The line numbers for syntax errors can be unreliable.
 
Old August 29th, 2003, 06:42 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ahh.. Nevermind my previous post, I've managed to get it working now.

BUT, the select statements does -not- work.

The only fields that are displayed using your method is whatever is in the last

<% Case Else
' do nothing
End Select %>

which is nothing..

I'm still stuck.
 
Old August 29th, 2003, 06:51 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know if I should laugh or cry, sorry to bother you with all these questions, but it's funny that right after I post my questions, I manage to get it working myself. Thanks to your code, it was nothing wrong with that - My first error was because of some "duff-string" as you called it, because I copied the code from this forum and right into my Frontpage. The last error was simply due to me overlooking your Ucase, and subsequently using lowercase in my Case.

Thanks, it's all looking very neat now! :)
 
Old September 3rd, 2003, 05:36 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

Hi
     If I execute a query "select * from customerinfo where name= 'steve' " and if there are no queries matching the criteria , then I would like to have a "no records available " message displayed. How do I do It?

thank You

 
Old September 3rd, 2003, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when you load it into a recordset (example: rs) then after you open it or fill it with a conn.execute(SQL) simply check it for the end of file:
Code:
If Not rs.EOF Then
   'do what you want with records
else
   'Show "No Messages" text
end if
...edited the code tag...
Chris





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP and HTML compactor BananaJim Classic ASP Professional 1 February 20th, 2007 10:10 AM
How can I add asp to html metalman923 HTML Code Clinic 1 October 5th, 2006 10:38 AM
Variable in ASP HTML? thenextbillgates ASP.NET 1.0 and 1.1 Basics 0 April 7th, 2006 09:28 PM
ASP code in html file Cinderella Classic ASP Basics 5 September 10th, 2004 03:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.