Avatar of Aleks
Aleks
Flag for United States of America asked on

Set value of checkbox when not checked

I have an insert statement that requires a value from a certain field.
This field is a checkbox that saves a text value into the database, the value in this case is "Mon"

   <input <%If (CStr((UserLogin.Fields.Item("loginmon").Value)) = CStr("Mon")) Then Response.Write("checked=""checked""") : Response.Write("")%> <%If (((UserLogin.Fields.Item("loginmon").Value)) = ("Mon")) Then Response.Write("checked=""checked""") : Response.Write("")%>  name="loginmon" type="checkbox" id="loginmon" value="Mon">

Open in new window


When its selected all works well, but if the checkbox is not selected it doesn't pass any value. I need it to pass:

"N" if not checked  and "Mon" if checked
ASPWeb DevelopmentHTML

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Dave Baldwin

Doesn't work that way.  Browsers won't pass a value for a checkbox that is not checked.  That is standard operation in all browsers.  Same is true for radio buttons.

You need to provide your own default value and change it only when you get a value from that checkbox.
Aleks

ASKER
got it. Can I do that in my update statement ?
I had this same page in ASP/JavaScript and this part worked, when moved to ASP/VB script it stopped working.
This is the line that updates on of the fields that has this issue:

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 3, Request.Form("loginmon")) ' adLongVarChar

The value that the checkbox passes is "Mon"  if not then its blank. How can I enter "" instead of null if not checked ?
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Aleks

ASKER
Thanks for the idea, this worked:

   MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 3, MM_IIF (Request.Form("loginmon"), Request.Form("loginmon"), null)) ' adLongVarChar
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Dave Baldwin

You're welcome, glad to help.