views:

73

answers:

2

Hi there,

I'm developing a website for Tenants to find properties. When they sign up, they can choose the property types that they are interested, for example: Apartment or House.

When a Tenant logs into their account, they can then do a search for properties. The search form is prepopulated with the values that they originally entered on sign up, for example: City, Postcode and so on.

The form also needs to display some checkboxes with the relevant boxes ticked for the Property Types that they selected on sign up. I'm having some problems getting this to work and wondered if there is anyone who could correct the code for me?

I believe I need to use an 'IN' statement so that the relevant checkboxes would be ticked, if the IDs for those properties are found in the CustomerReqPropertyType column. The CustomerReqPropertyType column is varchar(50) and as an example, if a user has selected Apartment and House, it is store in the row as 2, 4 (as there is a separate table with the Property Types.

This is the code I have on the page;

<%
  While (NOT rspropertytype.EOF)
%>

    <li>
      <input type="checkbox" name="txtPropertyType" id="txtPropertyType" value="<%=(rspropertytype.Fields.Item("PropertyTypeID").Value)%>"<% If Not rstenantrequirements.EOF Or Not rstenantrequirements.BOF Then %><%If (Not isNull((rstenantrequirements.Fields.Item("CustomerReqPropertyType").Value))) Then If (CStr(rspropertytype.Fields.Item("PropertyTypeID").Value) = CStr((rstenantrequirements.Fields.Item("CustomerReqPropertyType").Value))) Then Response.Write("")%><% End If ' end Not rstenantrequirements.EOF Or NOT rstenantrequirements.BOF %> />
      <label for="txtPropertyType"><%=(rspropertytype.Fields.Item("PropertyTypeTitle").Value)%></label>
    </li>

<%
  rspropertytype.MoveNext()
Wend
If (rspropertytype.CursorType > 0) Then
  rspropertytype.MoveFirst
Else
  rspropertytype.Requery
End If
%>

I would be very grateful for any help.

+1  A: 

In order for a checkbox to be checked the checked property must equal "checked".

e.g.

<input type="checkbox" name="something" value="somethingElse" checked="checked" />


I suspect that in your code the rspropertytype and rstenantrequirements recordsets could be consolidated into one recordset generated from one SQL statement.

e.g.

SELECT pt.*
     , CASE
         WHEN ISNULL(tr.CustomerReqPropertyType,0) = 0 THEN 0 
         ELSE 1 END AS [checked]
FROM propertytype AS [pt]
LEFT JOIN tenantrequirements AS [tr]
    ON pt.PropertyTypeID = tr.CustomerReqPropertyType
WHERE ...

Then your ASP code could be simplified as well.

e.g.

<%
While (NOT rs.EOF)
    Dim pID : pID = rs("PropertyTypeID")
    Dim pTitle : pTitle = rs("PropertyTypeTitle")
    Dim checked : checked = "" : If (rs("checked") = 1) Then checked = "checked"
%>
    <li>
     <input type="checkbox" name="txtPropertyType" id="txtPropertyType<%=pID%>" value="<%=pID%>" checked="<%=checked%>" />
     <label for="txtPropertyType<%=pID%>"><%=pTitle%></label>
    </li>
<%
    rs.MoveNext()
Wend
%>
CptSkippy
A: 

This is really hard to follow. First I'd break up that line to where your while is you can just set a variable and print that to page. I assume you're trying to set the checkbox checked. What I would do is make sure the value returned isn't null assuming this is a query that just returns the property type and you left joined it with the table that has the descriptions in it when they are set for the property in question. I don't see you ever print checked to the checkbox so it's never going to be checked anyway.

Jon
Hi Jon, yes i'm trying to set the relevant checkboxes to checked for the Property Types that users expressed an interest in.Originally, the user was only able to make one choice from a dropdown list when they signed up. But then it was apparent that people would like to choose more than one property type, so this page then became a list of checkboxes.
Neil Bradley
Understood. Do you need help with your SQL or the ASP portion though?
Jon