1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Checkbox input to an Access DB via ASP and JScript

Discussion in 'C#' started by Morn, Feb 19, 2007.

  1. #1
    I have is a set of HTML checkboxes and a Access database at the back end, when I retrieve the values of the checkboxes to process with Classic ASP I am running into a problem with undefined values.

    What I have discovered from research is that if a checkbox is not checked it will not passing anything as HTML checkboxes are either selected as 'on' or 'nothing'.

    However if it is checked then there is an on values passed and the yes/no field in the DB is checked.

    As you can imagine the DB needs a value and if an 'undefined' value is passed to a yes/no field, it results in a missing parameter error being sent.

    The compiled sql statement from a Response.Write command is:

    INSERT INTO tblHome (memberID, towncity, towndistance, towndirection, propertytype, flatfloor, flatblock, nobedrooms, nobathrooms, maxnoofpeople, carneeded, carexchange, smoking, swimpool, petcare, childrenallowed, plantcare, additionalinfo, picture)values ('2', 'London', '15', 'SE', 'Flat', '3', 'CC', '2', '2', '4', undefined, on, on, on, on, on, on, 'Hello', '');
    Code (markup):
    *note the undefined

    The question:

    Is there any way to make the 'nothing/undefined' value that is sent from the unchecked checkbox into a 'off' value so that the asp doesn’t fail?

    Please bear in mind that I only realy understand JavaScript and am very new to asp.

    Hope that makes sense, any help would be greatly appreciated.

    Thanks
    Graham
     
    Morn, Feb 19, 2007 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Just declare the value to off, then check if it exists-if it exists in the post, then the value is true or "on" in your case

    Also - make sure to 'on' rather than on when inserting characters instead of int or booleans

    so you would do

    val1 = false
    if lcase(trim(request.form("val1"))) = "on" then val1 = true

    and in your sql just include (val1) instead of the posted variable :)

    Hope this helps...
     
    ccoonen, Feb 19, 2007 IP