Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox value default to No when unchecked? 1

Status
Not open for further replies.

HardCoreCoder

Programmer
Feb 13, 2008
11
0
0
US
I have 2 checkboxes on my form. If they check them the value comes back as Yes. that works fine. What I want to do is have the value come back as No if the box isn't checked.

I tried it this way (in red) and it isn't working:

Code:
'Declare variables for the form input fields and the e-mail
  dim strAddr, replyTo, strSubject, strName
  dim strMsg, strDeptPhone, strPerspective
  dim strClassAssignment, strTermPaper
  dim strText

'Get input from the form and assign it to script variables
  strAddr = Trim(Request.form("user_email"))
  if strAddr <> "" then
	  replyTo = cstr(strAddr)
  end if

  strSubject = Request.form("user_subject")
  strName = Request.form("user_name")
  strMsg = Request.form("question")
  strDeptPhone = Request.form("dept_phone")
  strPerspective = Request.form("perspective")
  strClassAssignment = Request.form("class_assignment")

[COLOR=red]  if strClassAssignment <> "" then
  	strClassAssignment = No
  end if[/color]

  strTermPaper = Request.form("term_paper")

[COLOR=red]  if strTermPaper <> "" then
  	strTermPaper = No
  end if[/color]

  strText = "E-mail from: " & strName & vbCrLf &_
    "Concerning: " & strMsg & vbCrLf & vbCrLf &_
    "Dept. Phone: " & strDeptPhone & vbCrLf &_
    "Perspective: " & strPerspective & vbCrLf &_
    "Class Assignment: " & strClassAssignment & vbCrLf & "Term Paper: " & strTermPaper & vbCrLf & "."

 send_email()

Sorry for the stupid questions, I am new to ASP. You guys have been a great help! I very much appreciate you all.
 
I figured it out. There may be a better way of doing it but it works:

Code:
  strClassAssignment = Request.form("class_assignment")

If strClassAssignment = "Yes" Then
	strClassAssignment = "Yes"
Else
	strClassAssignment = "No"
End If

  strTermPaper = Request.form("term_paper")

If strTermPaper = "Yes" Then
	strTermPaper = "Yes"
Else
	strTermPaper = "No"
End If
 
Or
Code:
 strClassAssignment = Request.Form("class_assignment")
If strClassAssignment <> "Yes" Then
     strClassAssignment = "No"
End If

 strTermPaper = Request.Form("term_paper")
If strTermPaper <> "Yes" Then
     strTermPaper = "No"
End If

That says if it isn't "Yes" then it must be "No" -- otherwise it's obviously "Yes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top