473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Changing form's text field to checkbox

Related to my earleir post ... this is the same project to re-purpose the Classifieds application in BEGINNING ASP 3.0 (Wrox) to a comicbook database ...

This is a brainteaser that should have been easy to resolve but just doesn't seem to work for me ... The original application includes a form page for editing the details of an "item". In my case the item is a comicbook. The page functions just fine as long as I stick with text fields, but I run into problems when I try to change a couple of the text fields into checkboxes.

So, here's the code of the Item.asp page with text fields:

Expand|Select|Wrap|Line Numbers
  1. <%
  2.   Dim blnNew
  3.      ' detect whether the user is adding a new item or editing an existing one
  4.   Select Case Request.QueryString("Action")
  5.     Case "AddNew"
  6.       blnNew = True
  7.     Case "Edit"
  8.       blnNew = False
  9.   End Select
  10.  
  11. %>
  12.  
  13.     <div id="fullwidth">
  14.     <%
  15.       If blnNew Then 
  16.         Response.Write _ 
  17.           "<center><h1>Add an issue to the database</h1></center>" & _
  18.           "<center><p>Please add the following information for the issue you've just acquired</p> "
  19.       Else 
  20.         Response.Write _ 
  21.           "<center><h1>Edit data for issue you already have</h1></center>" & _
  22.           "<center><p>Please edit the information for this item</p> "
  23.         Dim rsItem 
  24.         Set rsItem = Server.CreateObject("ADODB.Recordset")
  25.         strSQL = "SELECT Title.titleName, Item.idItem, Item.issue, Item.[month], Item.[year], " & _
  26.       " Item.cond, Item.gcdb, Item.image, Item.cents, Item.have, Item.want, Item.note " & _ 
  27.       " FROM Title INNER JOIN Item ON Title.idTitle = Item.idTitle " & _
  28.       " ORDER BY titleName,month;"
  29.  
  30.         rsItem.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic, adCmdText 
  31.       End If
  32.     %>
  33.  
  34.     <form action="addItem.asp" method="post">
  35. <% 
  36.   If blnNew Then %>
  37.     <input type="Hidden" name="idItem" value=""> <%
  38.   Else %>
  39.     <input type="Hidden" name="idItem" value="<%= Request("Item") %>"> <%
  40.   End If
  41. %>
  42. <table border='0'>
  43.   <tr>
  44.     <td width=20% rowspan=8> </td>
  45.     <td align="right">Title:</td>
  46.     <td colspan="3"><input type="Text" name="titleName" 
  47.           value="<% If Not blnNew Then Response.Write rsItem("titleName") End If%>"
  48.           size="40" maxlength="75"></TD>
  49.   </tr>
  50.   <tr>
  51.     <td align="right">Issue:</td>
  52.     <td><input type="Text" name="issue" 
  53.          value="<% If Not blnNew Then Response.Write rsItem("issue") End If%>"
  54.          size="6"></td>
  55.     <td align="right">Condition:</td>
  56.     <td><input type="Text" name="cond" 
  57.          value="<% If Not blnNew Then Response.Write rsItem("cond") End If%>"
  58.          size="6"></td>
  59.   </tr>
  60.   <tr>
  61.     <td align="right">Month:</td>
  62.     <td><input type="Text" name="month" 
  63.          value="<% If Not blnNew Then Response.Write rsItem("month") End If%>"
  64.          size="6"></td>
  65.     <td align="right">Year:</td>
  66.     <td><input type="Text" name="year" 
  67.          value="<% If Not blnNew Then Response.Write rsItem("year") End If %>" 
  68.          size="6"></td>
  69.   </tr>
  70.  
  71.   <tr>
  72.     <td align="right">GCDB Page:</td>
  73.     <td colspan="3"><input type="Text" name="gcdb" 
  74.          value="<% If Not blnNew Then Response.Write rsItem("gcdb") End If%>"
  75.          size="40"></td>
  76.   </tr>
  77.   <tr>
  78.     <td align="right">Image:</td>
  79.     <td colspan="3"><input type="Text" name="image" 
  80.          value="<% If Not blnNew Then Response.Write rsItem("image") End If%>"
  81.          size="40"></td>
  82.   </tr>
  83.   <tr>
  84.     <td align="right">Cents:</td>
  85.     <td><input type="Text" name="cents" 
  86.          value="<% If Not blnNew Then Response.Write rsItem("cents") End If %>" 
  87.          size="6"></td>
  88.  
  89.     <td> </td>
  90.     <td> </td>
  91.  
  92.   </tr>
  93.   <tr>
  94.     <td align="right">Have:</td>
  95.     <td><input type="Text" name="have" 
  96.          value="<% If Not blnNew Then Response.Write rsItem("have") End If %>" 
  97.          size="6"></td>
  98.  
  99.     <td align="right">Want:</td>
  100.     <td><input type="Text" name="want" 
  101.          value="<% If Not blnNew Then Response.Write rsItem("want") End If %>" 
  102.          size="6"></td>
  103.   </tr>
  104.  
  105.   <tr>
  106.     <td align="right">Notes:</td>
  107.     <td colspan="3"><input name="note" type="text" 
  108.     value="<% If Not blnNew Then Response.Write rsItem("note") End If %>" 
  109.     size="40"></td>
  110.   </tr>
  111.   <tr>
  112.     <td> </td>
  113.     <td align=center colspan=4><BR><%
  114.       If Not blnNew Then %>
  115.         <input type="Submit" name="Delete" value="Delete Item"><%
  116.       End If %>
  117.  
  118.       <input type="Submit" 
  119.          value="<% If blnNew Then %>Add New Item<% Else %>Update Item<% End If %>">
  120.  
  121.       <input type="Reset"></TD>
  122.   </TR>
  123. </table>
  124. </form>
The object here is to create a dual-purpose page that can be used to add new items to the database and to edit existing items.

My problem arises when I try to change the "cents", "have" and "want" fields to checkboxes. This bit of code almost works:

Expand|Select|Wrap|Line Numbers
  1. 106   <td align="right">Cents:</td>
  2. 107    <td><% If rsItem("cents") then strChecked = " checked" End If %>
  3. 108    <input type="checkbox" name="cents" value="<%=rsItem("cents")%>"<%=strChecked%>>
  4.     </td>
  5.     <td> </td>
  6.     <td> </td>
  7.  
  8.   </tr>
  9.   <tr>
  10.     <td align="right">Have:</td>
  11.     <td><% If rsItem("have") then strChecked = " checked" End If %>
  12.     <input type="checkbox" name="have" value="<%=rsItem("have")%>"<%=strChecked%>>
  13.     </td>
  14.     <td align="right">Want:</td>
  15.     <td><% If rsItem("want") then strChecked = " checked" End If %>
  16.     <input type="checkbox" name="want" value="<%=rsItem("want")%>"<%=strChecked%>>
  17.     </td>
(The variable "strChecked" is DIMmed further up the page!)

I say "almost" because it works fine (returns a checked checkbox when the related field in the database is checked) when I'm looking at an existing database entry, but it fails when I try to use it to add an entirely new item, with this error message:

Expand|Select|Wrap|Line Numbers
  1. Microsoft VBScript runtime  error '800a000d'
  2.  
  3. Type mismatch
  4.  
  5. /publishing/comics/collecting/admin/item2.asp, line 107
If anyone knows how to solve this problem, I'd be ever so grateful ...

Best,

peck2000
Jul 2 '07 #1
1 2601
jhardman
3,406 Expert 2GB
I'm not sure, I'm having a little difficulty picturing the problem, but it seems that the problem lies between how different programs interpret boolean variables. for example, If I remember right, SQL SERVER recognizes 0 and 1, but Access recognizes "True" and "False", whereas HTML checkboxes are interpretted as "on" or "". Could these distinctions be causing the problem?

By the way, I noticed that you don't reset the variable strChecked after it is used. Each time you say something like
Expand|Select|Wrap|Line Numbers
  1. if [some condition] then strChecked = " checked" end if
and then use it again. If the first condition is satisfied then each subsequent time you will get " checked" because you never tell it to reset (strChecked = "") after you use it.

Jared
Jul 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pat Scott | last post by:
I am looking for a general purpose javascript snippet that enables me to <div> or <span> HTML to make portions of the form be hidden and then appear. The form contains about 12 sections and some...
5
by: Wouter | last post by:
Hi, I had a javscript what does the follow. When a checkbox is yes then i will see a form field. When a checkbox is no i dont see the form field. Can somehelp me for that script ? Greets...
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
6
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
4
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a php driven database program for a literacy program, it will allow them to keep track of classes and students, the part i am strugling with is adding new classes, the...
5
by: hotrod57 | last post by:
I have this php function that reads a text file for input to create a form. I am trying to get the form to print out the data on a separate page, but all I get is a blank page. Am I calling the page...
1
by: hotrod57 | last post by:
I am trying to append the results from a form to a text file. My code is supposed to print out the results on one page, and append the results to another page each time data is entered on the form...
3
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
9
by: Hamayun Khan | last post by:
Hi I m using form like below <form action='' method = post> <input type=text name=txt id=txt> <select name=region id=region multiple> <option value=1>ONE</option> <option value=2>Two</option>...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.