Hello Everyone, I need some code which will replace NULL with 0 in the database when a checkbox in unchecked by the user, when the page is submitted... even if the checkbox is not touched by the user, that means it remains unchecked, since they're all unchecked to begin with, even then it should change to 0 when the user moves on to the next page....
This application has 3 pages and you can navigate either with Previous or Next buttons or by clicking the page number... All the pages are posted to the same validation page called save.asp and this page updates the database every time a user leaves the page...
The code on my first page has checkboxes which display as NULL in the database if they are not checked by the user and 1 if they are checked
Here is the code on the first page:
<form action="save.asp" id="OPICForm" name="OPICForm" method="post" onSubmit="return ValidateSubmit();">
<input type="checkbox" id="LearnConference" name="LearnConference" value = <%=sLearnConference%> <%=sLearnConferenceChecked
%>>Conference<BR>
<input type="checkbox" id="LearnWebsite" name="LearnWebsite" value = <%=sLearnWebsite%> <%=sLearnWebsiteChecked%>>
OPIC Web Site<BR>
<INPUT type="submit" style="width:75px;" value="Previous" onclick="setInputValue(doc
ument.OPIC
Form._targ
et,'Previo
us');">
Jump to page: [<A href="javascript:SubmitFor
m('00');">
Intro</A>]
<STRONG>[1]</STRONG> [<A
href="javascript:SubmitFor
m('02');">
2</A>] [<A
href="javascript:SubmitFor
m('03');">
3</A>] [<A
href="javascript:SubmitFor
m('04');">
Review</A>
] <INPUT type="submit" style="width:75px;" value="Next" onclick="setInputValue(doc
ument.OPIC
Form._targ
et,'Next')
;">
<BR>
<input type = "submit" value = "Save and Close" id = "SaveClose" onclick="setInputValue(doc
ument.OPIC
Form._targ
et,'SaveCl
ose');">
<%
sqlValues = "SELECT * FROM tableName WHERE FK_id=" & id
set rsValues = Server.CreateObject("ADODB
.Recordset
")
with rsValues
.open sqlValues, objConn,3,3
if .Recordcount=1 then
sLearnConference = .Fields("LearnConference")
sLearnWebsite = .Fields("LearnWebsite")
end if
.close
end with
if .Fields("LearnConference")
=true then sLearnConferenceChecked = " CHECKED " else sLearnConferenceChecked = "" end if
if .Fields("LearnWebsite")=tr
ue then sLearnWebsiteChecked = " CHECKED " else sLearnWebsiteChecked = "" end if
%>
<script>
function setInputValue(obj,value){
var use_default=(arguments.len
gth>1)?arg
uments[1]:
false;
if(isArray(obj)&&(typeof(o
bj.type)==
"undefined
")){
for(var i=0;i<obj.length;i++){
setSingleInputValue(obj[i]
,value);
}
}
else
{
setSingleInputValue(obj,va
lue);
}
}
function setSingleInputValue(obj,va
lue){switc
h(obj.type
){case 'radio': case 'checkbox': if(obj.value==value){obj.c
hecked=tru
e;return true;}else{obj.checked=fal
se;return false;}case 'text': case 'hidden': case 'textarea': case 'password': obj.value=value;return true;case 'select-one': case 'select-multiple':
var o=obj.options;for(var i=0;i<o.length;i++){if(o[i
].value==v
alue){o[i]
.selected=
true;}else
{o[i].sele
cted=false
;}}return true;}alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");return false;}
</script>
CODE ON the save.asp page (the page it's posting to:)
%
'Angie H. -- Test checkboxes
dim LearnConf, Website
'FIRST CHECKBOX -- CONFERENCE
If Request.Form("LearnConfere
nce") <> 1 then
LearnConf = ""
Else
LearnConf = "CHECKED"
End if
if((LearnConf) = "CHECKED") then
Request.Form("LearnConfere
nce") = 0
end if
'SECOND CHECKBOX -- WEBSITE
If Request.Form("LearnWebsite
") <> 1 then
Website = ""
Else
Website = "CHECKED"
End if
if((Website ) = "CHECKED") then
Request.Form("LearnWebsite
") = 0
end if
%>
Can you help me figure out what's wrong with this code, why it does not change the database value from NULL to 0 when the checkbox is unchecked?
I get this error when I click NEXT:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'Request.Form'
/angieapps/52/save_sv.asp,
line 18
and it's coming from this line:
Request.Form("LearnConfere
nce") = 0
I used this Request.Form("LearnConfere
nce") before without an error, but now it gives me an error because I try to change its value?!?!
Any ideas?