View Full Version : Checkboxes
Trumpet
05-28-2003, 09:04 PM
Hi,
I have a question similar to testing Kendells previous question on checkboxes. I need to provide an update form that is populated by a record in a database that allows the user to update his/her information.
However, I'm using Session variables to hold values for the existing fields in the form and not creating a new record set on this page.
How do I show the checkboxes as selected for the values in the field from the database using the session variable? Also, note that there are multiple values for the field which are separated by commas in the database field. The database is Access 2000.
Thanks, in advance, for your assistance.
Trumpet
Frank
05-29-2003, 12:23 AM
Are you saying that each individual checkbox has multiple values? Or are you saying that all of the checkbox values are stored in one field in the database table?
I'm not sure how you have the values stored in the database, but I'm guessing you could do something like this:
<input type="checkbox" name="c1" value="<%=Session("YourVariableName")%>" <% If Session("YourVariableName") <> "" Then %> CHECKED <% End If %>>
I could be way off with that. It's difficult to say without knowing how those values are stored :}
Trumpet
05-29-2003, 07:12 AM
Thanks for responding...
Allof the checkbox values are stored in one field in the database table. I will try your solution.
Thanks again!
Trumpet
Trumpet
05-29-2003, 08:09 AM
Ok, I tried Frank's suggestion, but it doesn't seem to work. Any other suggestions are much appreciated!
Thanks.
Laurie
Zebulin
05-29-2003, 08:36 AM
<html>
<body>
// YOUR FORM WITH THE CHECK BOXES
<form name='x'>
<input type='checkbox' name='val1' value='1'>
<input type='checkbox' name='val2' value='2'>
<input type='checkbox' name='val3' value='3'>
<input type='checkbox' name='val4' value='4'>
</form>
<script language="Javascript">
// FUNCTION TO CHECK VALUES FROM THE SESSION
function chkDefault(obj){
var Arr = ("<%= Session("yourvalue") %>").split(",");
for ( i = 0 ; i < Arr.length ; i++ ){
if ( rmspaces(obj.value) == rmspaces(Arr[i]) ) {
obj.checked = true;
i = Arr.length ;
}
}
}
// FUNCTION TO TRIM SPACES
function rmspaces(x) {
var leftx = 0;
var rightx = x.length -1;
while ( x.charAt(leftx) == ' ') leftx++;
while ( x.charAt(rightx) == ' ') --rightx;
var q = x.substring(leftx,rightx+1);
if ( (leftx == x.length) && (rightx == -1) ) q ='';
return(q)
};
// LIST OF CHECKBOXES YOU WANT TO COMPARE TO THE SESSION VARIABLE.
//SESSION VARIABLE MAY CONTAIN COMMA SEPERATED VALUES
chkDefault(document.x.val1);
chkDefault(document.x.val2);
chkDefault(document.x.val3);
chkDefault(document.x.val4);
</script>
Doesnt seem to work ?.. then show us ur code ...
hi all,
if you have asession enabled websit shurly you coul'd use coockie.
here is a code i use that saves the last search's parameters to acoockie varriable.
case "bos"
start_day = trim(request("start_day"))
start_month = trim(request("start_month"))
start_year = trim(request("start_year"))
technician = trim(request("technician"))
theteam = session("team")
dim lastsearg()
if technician = "" then
last_search = request.Cookies("lastsearch")
if not last_search = "" then
lastsearch = split(request.Cookies("lastsearch"),",")
start_day = lastsearch(0)
start_month = lastsearch(1)
start_year = lastsearch(2)
technician = lastsearch(3)
end if
else
lastsearch = start_day &","&start_month&","&start_year&","&technician&","&theteam
response.Cookies("lastsearch") = lastsearch
end if
set rs = con.execute("select id, name from technicians where team = '" & session("team") & "'")
themen = rs.getrows()
set rs = nothing
set rs = con.execute("select technicians.team, shifts.shift_date from technicians, shifts where technicians.id = shifts.tech_id and technicians.team = '" & theteam & "' order by shifts.shift_date desc")
lastdate = rs("shift_date")
lastmonth = lastdate -30
set rs = nothing
if start_day = "" or start_month = "" then
sql = "select technicians.name, technicians.id, "
sql = sql & "technicians.team, shifts.shift_date, shifts.remarks, shifts.id from technicians, shifts where technicians.id = shifts.tech_id "
sql = sql & "and technicians.team = '" & theteam & "' and shifts.shift_date between #" & lastdate & "# and #" & lastmonth & "# order by shifts.shift_date"
set rs = con.execute(sql)
shifts = rs.getrows()
set rs = nothing
else
start_date = start_day & "/" & start_month & "/" & start_year
start_date = hebdate(start_date)
if technician = "all" then
sql = "select technicians.name, technicians.id, "
sql = sql & "technicians.team, shifts.shift_date, shifts.remarks, shifts.id from technicians, shifts where technicians.id = shifts.tech_id "
sql = sql & "and technicians.team = '" & theteam & "' and shifts.shift_date between #" & lastdate & "# and #" & start_date & "# order by shifts.shift_date"
set rs = con.execute(sql)
shifts = rs.getrows()
set rs = nothing
else
sql = "select technicians.name, technicians.id, "
sql = sql & "technicians.team, shifts.shift_date, shifts.remarks, shifts.id from technicians, shifts where technicians.id = shifts.tech_id "
sql = sql & "and shifts.shift_date between #" & lastdate & "# and #" & start_date & "# and technicians.id = " & technician & " order by shifts.shift_date"
set rs = con.execute(sql)
shifts = rs.getrows()
set rs = nothing
end if
end if
%>
Trumpet
05-30-2003, 07:02 AM
Thanks for all your suggestions. However, nothing seems to be working to hold those values!
Please take a look at this code to see what I can do to make this happen.
The main.asp page is just a menu page that the user is directed to upon login. When they login, the script sets the session values based on a database query. This works fine.
The update.asp is the form that needs to hold the values when visited from the main.asp page.
The updateok.asp script updates the data in the database, re-sets the session values, then redirects to the main.asp page. The user can then click on a link to update.asp to make changes. I need the update form to hold the values for drop-downs and checkboxes.
All files are included in the attached zip file.
Thanks as usual for your assistance!
Trumpet
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.