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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox not recognized as unchecked, new value being passed

Status
Not open for further replies.

spastica

Programmer
Sep 27, 2002
72
GB
i have a form where the user can click a checkbox, and when the form is submitted, that value is passed into a session variable. the user can go back and edit the form and uncheck the checkbox.

the problem is, when the checkbox is unchecked, the session still holds the old value as if the box were submitted checked, and does not clear or overwrite that value. the other form fields (textbox and radio buttons) work fine.

is there a way to solve this?!
 
on the second page, how are you checking the checkbox?

Try-


if request("myCheckbox") = "on" then
session("itsChecked") = true
else
session("itsChecked") = false
end if

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 

thank you, that works fine!

i am assigning session variables through this method, which loops through the form fields and assigns accordingly:

For Each Field in Request.Form
TheString = "Session(""" & Field & """)= ParseQuotes2(Request.Form(""" & Field & """))"
if Field="submit" then
TheString=""
end if
Execute(TheString)
Next


but now I have added the following outside this loop to capture the checkbox values:

'TO GET CORRECT VALUE FOR WATER: MUNICIPAL WATER CHECKBOX
if request("Sec_municipalWater") = "on" then
session("Sec_municipalWater") = "Municipal Water"
else
session("Sec_municipalWater") = ""
end if

'TO GET CORRECT VALUE FOR WATER: WELL CHECKBOX
if request("Sec_well") = "on" then
session("Sec_well") = "Well"
else
session("Sec_well") = ""
end if

'TO GET CORRECT VALUE FOR SEWEAGE:SEWER CHECKBOX
if request("Sec_sewers") = "on" then
session("Sec_sewers") = "Sewers"
else
session("Sec_sewers") = ""
end if

'TO GET CORRECT VALUE FOR SEWAGE: SEPTIC TANK CHECKBOX
if request("Sec_septicTank") = "on" then
session("Sec_septicTank") = "Septic Tank"
else
session("Sec_septicTank") = ""
end if


Previoulsy, I had it so that the checkboxes values were the session variable values (so for example, the value of the water checkbox was "water" - written into the checkbox code) I have now removed the "value" line from all checkboxes and assign the values as above.

Is there another way to do this so that I don't have to go outside the inital loop and don't have to maintain the code on 2 seperate pages?
 
Is there another way to do this so that I don't have to go outside the inital loop and don't have to maintain the code on 2 seperate pages?

You could use javascript on the first page to transfer the values to hidden form fields when they are checked and clear the field (or remove it) when they are unchecked. Depends on how involved you want your client-side scripting...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
thanks :)

I think i'll stick with my current method, unless the number of checkboxes increases - right now it's pretty manageable!

thanks for your help! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top