473,568 Members | 3,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing form's text field to checkbox

5 New Member
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
  11. %>
  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;"
  30.         rsItem.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic, adCmdText 
  31.       End If
  32.     %>
  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>
  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>
  89.     <td> </td>
  90.     <td> </td>
  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>
  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>
  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 %>
  118.       <input type="Submit" 
  119.          value="<% If blnNew Then %>Add New Item<% Else %>Update Item<% End If %>">
  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>
  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'
  3. Type mismatch
  5. /publishing/comics/collecting/admin/item2.asp, line 107
If anyone knows how to solve this problem, I'd be ever so grateful ...


Jul 2 '07 #1
1 2630
3,406 Recognized Expert Specialist
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.

Jul 3 '07 #2

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

Similar topics

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 sections can contain subsections. When the user clicks on a checkbox, I want previously hidden text boxes, radio buttons, text, drop down menus, and...
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 Wouter
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 the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
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 allow the user to type in a value. Also, I would like the 2nd option only editable if the button for that option is selected. All I can seem to...
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 add_class page looks like: <body> ADD CLASS<br> Class Title: <input type="text" value="class_title"><br> Class Name: <input type="text"...
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 correctly, or is this even possible to do? <form action="phpform.php" method=POST> <?php $field=array(); $type=array(); $lines =...
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 and the submit button is hit. Unfortunately, it is only printing out the message acknowledging the submit button--no data on either form. Here is the...
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 in \anmeldung2.cfm: line 404
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> <option value=3>Three</option> <option value=4>Four</option>
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.