DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Inserting Checkboxes Into Yes/No Field In Access Database (JavaScript)

Hybrid View

  1. #1
    Cindy Guest

    Inserting Checkboxes Into Yes/No Field In Access Database (JavaScript)



    I'm working on a demonstration project using ASP written with
    JavaScript and an Access database. This part of the project requires
    subscribers to develop a profile. Most of the information is via a
    textbox, and I'm not having any problem processing it and storing it
    in the database, but I'm stuck at checkboxes.

    One book suggests defining the checkboxes with the same name,
    different values. I've done that:

    <input type="checkbox" name="chkIntersts" id="chkIntersts"
    value="events"
    />Upcoming Events<br />
    <input type="checkbox" name="chkIntersts" id="chkIntersts"
    value="classes"
    />New Classes<br />
    <input type="checkbox" name="chkIntersts" id="chkIntersts"
    value="internships" />Internships<br />

    I can print the areas of interest checked to a confirmation form:

    <p>Interests are <%= Request.Form("chkIntersts") %></p>

    What I can't do -- and I've search for hours on the internet -- is
    update the database for these checkboxes.

    I have set the default value for the checkboxes to NO, since only the values
    of checked boxes will be passed to the server. I know (I think) that I can
    inspect the form's checkbox property and extract the values, but then I need
    some way to convert those values into the field names of the database.

    So, my problem is that I don't know how to access the values, and then work
    with them in any kind of meaningful way. I know how to build a basic INSERT
    query (as I said, the text boxes have worked out fine) but I'm clueless about
    building the SQL query for the checkboxes. How do I get the appropriate field
    name into the query, so that I can read the box's value into the VALUE part
    of the query? (I only barely know what I'm talkig about, so its possible
    that this paragraph doesn't make sense!) How do I get the value translated
    into Y/N?

    Eventually, I'm also going to have to know how to read a record from
    the database into a form ... If someone want to edit their profile,
    I'd like for the form to come up with it's current settings ... but I
    can wait for this!

    I'd appreciate any guidance!

    Thanks, Cindy

  2. #2
    JS Guest

    Re: Inserting Checkboxes Into Yes/No Field In Access Database (JavaScript)


    hmmmm...isn't ASP written in VBScript????

    I have 2 solutions...because you are processing the checkboxes in different
    ways.

    #1 give each checkbox have a different name. The reason is this. You want
    to store the value of each of them in the database right? Well, if you have
    a different name for each checkbox, and have a different field in your database
    (to store the on/off or yes/no or whatever) for each of the checkboxes.
    It's a little extra DB work that makes the programming a lot easier.
    if var = "on" then
    var = "yes"
    else
    var = "no"
    end if
    SQL - insert into table (field1) values (" & var & ")"
    notice there are no ' characters....
    you would access it just like any other value from the DB when pulling it
    out...
    if objrec("field1") = "yes" then
    <checkbox = checked> that was abbreviated
    end if

    OR

    #2 change your db so that the "checkbox" field is a text field instead.
    Do this because you are assigning values to the checkboxes such as "events"
    and "classes" so if you response.write your request from the page you should
    get events,classes if both are checked.....and insert this as you would insert
    text into the DB....

    to get the data out, use the InSTR() method....
    so

    if instr(objrec("field1"),"classes") = "True" then
    ....hmtl for checkbox to be checked....
    end if

    hope this helps...if you have more questions just post them.....

    "Cindy" <webjunque@hotmail.com> wrote:
    >
    >
    >I'm working on a demonstration project using ASP written with
    >JavaScript and an Access database. This part of the project requires
    >subscribers to develop a profile. Most of the information is via a
    >textbox, and I'm not having any problem processing it and storing it
    >in the database, but I'm stuck at checkboxes.
    >
    >One book suggests defining the checkboxes with the same name,
    >different values. I've done that:
    >
    ><input type="checkbox" name="chkIntersts" id="chkIntersts"
    >value="events"
    >/>Upcoming Events<br />
    ><input type="checkbox" name="chkIntersts" id="chkIntersts"
    >value="classes"
    >/>New Classes<br />
    ><input type="checkbox" name="chkIntersts" id="chkIntersts"
    >value="internships" />Internships<br />
    >
    >I can print the areas of interest checked to a confirmation form:
    >
    ><p>Interests are <%= Request.Form("chkIntersts") %></p>
    >
    >What I can't do -- and I've search for hours on the internet -- is
    >update the database for these checkboxes.
    >
    >I have set the default value for the checkboxes to NO, since only the values
    >of checked boxes will be passed to the server. I know (I think) that I can
    >inspect the form's checkbox property and extract the values, but then I

    need
    >some way to convert those values into the field names of the database.
    >
    >So, my problem is that I don't know how to access the values, and then work
    >with them in any kind of meaningful way. I know how to build a basic INSERT
    >query (as I said, the text boxes have worked out fine) but I'm clueless

    about
    >building the SQL query for the checkboxes. How do I get the appropriate

    field
    >name into the query, so that I can read the box's value into the VALUE part
    >of the query? (I only barely know what I'm talkig about, so its possible
    >that this paragraph doesn't make sense!) How do I get the value translated
    >into Y/N?
    >
    >Eventually, I'm also going to have to know how to read a record from
    >the database into a form ... If someone want to edit their profile,
    >I'd like for the form to come up with it's current settings ... but I
    >can wait for this!
    >
    >I'd appreciate any guidance!
    >
    >Thanks, Cindy



  3. #3
    Cindy Guest

    Re: Inserting Checkboxes Into Yes/No Field In Access Database (JavaScript)


    "JS" <jakesmsu@hotmail.com> wrote:
    >
    >hmmmm...isn't ASP written in VBScript????


    The default language for ASP is VBScript, but there is native support for
    both JScript and VBScript. However, ActiveX scripting plug-ins are available
    for REXX, PERL, and Python, so they can also be used to develop Active Server
    Pages.

    Thanks for the prompt answer to my question. I'm going to start working on
    it this afternoon.

    Cindy


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center