Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 Using Check boxes to compile a field input
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 03 July 2002 :  06:45:09  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Hi again (esp. FrutZLe!)

Having successfully changed the information that is requested at registration, I've got another request. Currently, all information is entered via enter combo boxes or free text type.

I'd got 1 area that could be 1 of 9 possible answers, or any combination of them. Now, I'd like to keep the data in a controlled format so I can see the results easily.

I could make a massive combo list of all the possible options, but that would be stupid.

What I'd like to have a 9 check boxes that the user can tick if that area is relevant. The page would then add the text that is relevant to that check box to a master field, along with a comma to seperate the items. I'll demonstate in a diagram:




I hope that makes sense. The text is just the values of the boxes that are checked made into 1 string seperated by a comma.

When the profile displays, this sting would be displayed- but when you edit you profile, the checked boxes would be shown.

I can see this being very easy on the one hand, but a bit tricky on the other.

Anyone that knows Snitz/ASP well care to lend a hand in making this happen?

Thanx in advance

Jamez

Moved by ruirib
I'm moving this to the MOD W/O code forum because this is a request for a change to the base that requires a certain degree of effort to be achieved



Edited by - ruirib on 03 July 2002 07:33:26

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 03 July 2002 :  08:35:07  Show Profile
The problem is the multiple choice box. If you'd use RadioButtons and thereby only allow one choice, things would be a lot easier.
I'll see if I can come up with an easy way to do what you want.

Roland

http://www.frutzle.com

Snitz Exchange | Do's and Dont's
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 03 July 2002 :  08:42:47  Show Profile
Should be easy enough if on the form, you name the checkboxes the same thing. When the form data is posted, the values for the checkboxes are are strung together separated by commas (I believe), so a Request.Form("MyCheckbox") contains text such as "option1,option3,option6" for only the options selected. That entire value *could* be inserted into a database into one field.

Then, on the profile page for viewing only, you could just write that one field to the page. The tricky part is how to make the check boxes appear checked when someone goes to edit their profile. To do this, you would grab the value from the db, tack a comma on the front and end of that string, and as you are writing the html for the checkboxes put an if statement that looks at that string for ",optionX," if it is there put the checked value on the check box, if not don't.

Hope that made sense.

Nikkol
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  06:51:20  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Yes, that did Nikkol and your idea for the solution was exactly what I was intending.

Having the boxes checked again when someone edit's their profile would happen in an ideal world, but wouldn't have to happen.

Would it be possible to put some sort of arguement in where by:

If some check boxes are ticked
field string = option1,option3 (as above)
else
field value = what is was before the edit
end if


I assume that all you would need to do is dump the current string into a varible before the update so you could you it again afterward.

Does this seem possible?

Jamez
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 04 July 2002 :  10:10:40  Show Profile
Why not just try to check the boxes using if statements for each checkbox?

Whatever you field is that you store them in, you would grab that from the db and lets say you set it equal to a variable named strOptions. Then make strOptions = "," & strOptions & ","

Then where ever you display your 9 check boxes, each one would look like:

<input type="checkbox" name="myOptions" value="option1" <% if InStr(strOptions, ",option1,") then response.write("checked") %>>
<input type="checkbox" name="myOptions" value="option2" <% if InStr(strOptions, ",option2,") then response.write("checked") %>>

and so on.

Nikkol
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  11:22:41  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Yes Nikkol, that would be fine- I'm not 100% fussed about how streamline the code is and the server's not that hot and the info not that important.

So, assuming that I'm going to do it your way with 10 options, and was going to use the field that used to be for "stat" (var name M_STATE), could you please write the code for that- I've not got a clue about ASP.

Mu guess would be:


<input name="listen" value="<% =rs("M_STATE") %>
<input type="checkbox" name="myOptions" value="option1" <% if InStr(strOptions, ",option1,") then response.write("checked") %>>
<input type="checkbox" name="myOptions" value="option2" <% if InStr(strOptions, ",option1,") then response.write("checked") %>>
<input type="checkbox" name="myOptions" value="option3" <% if InStr(strOptions, ",option1,") then response.write("checked") %>>
<input type="checkbox" name="myOptions" value="option4" <% if InStr(strOptions, ",option1,") then response.write("checked") %>>


I know that's not it, but I'm not sure how I would open the section for check boxes, I think I need a box on ASP!

Canb someone correct me?

Jamez
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 04 July 2002 :  11:31:17  Show Profile
what are your 10 options?

have you gotten the check boxes to write to the database yet? (it sounded like you had earlier)

Nikkol
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  11:48:18  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Sorry Nikkol, you credit me with far to much ASP knowledge!

I know my 10 options, but have done nothing about getting check boxes onto the page, let alone writing to the db!!!

The options would be: Friday Night, Saturday Morning, Saturday Afternoon, Saturday Evening, Saturday Night, Sunday Morning, Sunday Afternoon, Sunday Evening, Sunday Night and Not Frequently

I can't see the saving to the db being a problem, couldn't we make a string out of the check box names, write that to a (hidden) text box then write that to the db?

Just a thought, and thanx for your time.

Jamez
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 04 July 2002 :  11:51:19  Show Profile
Using the checkboxes would be easier. Just to be sure, you want to use the State field, yes?

Nikkol
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  11:56:56  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Yes, it is for the state field, and I don't mind what sort of boxes I use, as long as the user could enter "yes" to more than one option as that is VERY likely.

Jamez
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 04 July 2002 :  12:12:26  Show Profile
Try this and see how it works. Find in inc_profile the section where state is specified and add the parts in red. Remove the sticken out parts in green:

if strState = "1" then
strChkState = "," & rs("M_STATE") & ","
%>
<tr>
<td bgColor="<% =strPopUpTableColor %>" align=right nowrap valign=top><b><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">StateWhatever you are calling this field: </font></b></td>
<td bgColor="<% =strPopUpTableColor %>"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><input name="State" value="<% =rs("M_STATE") %>">
<input name="State" type="checkbox" value="Friday Night" <% if InStr(strChkState,",Friday Night,") then response.write(" checked")%>> Friday Night<br>
<input name="State" type="checkbox" value="Saturday Morning" <% if InStr(strChkState,",Saturday Morning,") then response.write(" checked")%>> Saturday Morning<br>
<input name="State" type="checkbox" value="Saturday Afternoon" <% if InStr(strChkState,",Saturday Afternoon,") then response.write(" checked")%>> Saturday Afternoon<br>
<input name="State" type="checkbox" value="Saturday Evening" <% if InStr(strChkState,",Saturday Evening,") then response.write(" checked")%>> Saturday Evening<br>
<input name="State" type="checkbox" value="Saturday Night" <% if InStr(strChkState,",Saturday Night,") then response.write(" checked")%>> Saturday Night<br>
<input name="State" type="checkbox" value="Sunday Morning" <% if InStr(strChkState,",Sunday Morning,") then response.write(" checked")%>> Sunday Morning<br>
<input name="State" type="checkbox" value="Sunday Afternoon" <% if InStr(strChkState,",Sunday Afternoon,") then response.write(" checked")%>> Sunday Afternoon<br>
<input name="State" type="checkbox" value="Sunday Evening" <% if InStr(strChkState,",Sunday Evening,") then response.write(" checked")%>> Sunday Evening<br>
<input name="State" type="checkbox" value="Sunday Night" <% if InStr(strChkState,",Sunday Night,") then response.write(" checked")%>> Sunday Night<br>
<input name="State" type="checkbox" value="Not Frequently" <% if InStr(strChkState,",Not Frequently,") then response.write(" checked")%>> Not Frequently

</font></td>
</tr>
<%
end if


Nikkol
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  12:40:37  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Thanx Nikkol, tried that, the code I entered being:
 <td bgColor="<% =strPopUpTableColor %>" align=right nowrap><b><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">When 
do you listen to Njoi? </font></b></td>
<td bgColor="<% =strPopUpTableColor %>"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">

if strState = "1" then
%>
strChkState = "," & rs("M_STATE") & ","
<tr>
<td bgColor="<% =strPopUpTableColor %>" align=right nowrap valign=top><b><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">When do you lock: </font></b></td>
<td bgColor="<% =strPopUpTableColor %>"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">
<input name="State" type="checkbox" value="Friday Night" <% if InStr(strChkState,",Friday Night,") then response.write(" checked")%>> Friday Night<br>
<input name="State" type="checkbox" value="Saturday Morning" <% if InStr(strChkState,",Saturday Morning,") then response.write(" checked")%>> Saturday Morning<br>
<input name="State" type="checkbox" value="Saturday Afternoon" <% if InStr(strChkState,",Saturday Afternoon,") then response.write(" checked")%>> Saturday Afternoon<br>
<input name="State" type="checkbox" value="Saturday Evening" <% if InStr(strChkState,",Saturday Evening,") then response.write(" checked")%>> Saturday Evening<br>
<input name="State" type="checkbox" value="Saturday Night" <% if InStr(strChkState,",Saturday Night,") then response.write(" checked")%>> Saturday Night<br>
<input name="State" type="checkbox" value="Sunday Morning" <% if InStr(strChkState,",Sunday Morning,") then response.write(" checked")%>> Sunday Morning<br>
<input name="State" type="checkbox" value="Sunday Afternoon" <% if InStr(strChkState,",Sunday Afternoon,") then response.write(" checked")%>> Sunday Afternoon<br>
<input name="State" type="checkbox" value="Sunday Evening" <% if InStr(strChkState,",Sunday Evening,") then response.write(" checked")%>> Sunday Evening<br>
<input name="State" type="checkbox" value="Sunday Night" <% if InStr(strChkState,",Sunday Night,") then response.write(" checked")%>> Sunday Night<br>
<input name="State" type="checkbox" value="Not Frequently" <% if InStr(strChkState,",Not Frequently,") then response.write(" checked")%>> Not Frequently
</font></td>
</tr>
<%
end if


I think the problem lies within the bit in red. I wasn't sure what I needed from a formatting point of view, and what I can delete as it occurs in your script.

Can you direct? Thanx

(P.S. I'm going to leave the office in 10 mins or so, and might not be back on until tomorrow- just so you know.)

Jamez

Edited by - ParaDoX on 04 July 2002 12:41:49
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 04 July 2002 :  12:56:24  Show Profile
first of all, the part in red you are placing with ASP code ... it needs to be outside of it.
Just to see if you can get it working, REMOVE that part in red that you highlighted
(it wasn't part of the code I gave you anyway).
plus, you are placing <td> tags in there that will mess up your table.

second, you didn't copy my code carefully. Check this line:

strChkState = "," & rs("M_STATE") & ","

and put it BEFORE then %> as I had done in my previous post.

Nikkol

Edited by - Nikkol on 04 July 2002 12:57:31
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  12:57:14  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
OK, I've done a little more myself and have it working now, or at least the start of it.

The boxes appear, the data is stored, with a "," between each one and that is displayed.

But, there is a little bit of "left over code" @ the top of the table and when you edit the profile, you need to reselect when you listen.

I know we can tick the boxes again, but could we do it that if they are all unticked, the value isn't changed, or is that too hard?

He is a link so you may see the "left over code" :

http://www16.brinkster.com/njoifm/register.asp?mode=Register

Thanx again, I couldn't have got this far without your help Nikkol

Jamez
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 04 July 2002 :  12:58:47  Show Profile
it's because of what i mentioned in the previous post.

and you're welcome ... glad to help.

Nikkol

Edited by - Nikkol on 04 July 2002 12:59:41
Go to Top of Page

ParaDoX
New Member

United Kingdom
84 Posts

Posted - 04 July 2002 :  13:01:21  Show Profile  Visit ParaDoX's Homepage  Send ParaDoX an AOL message  Send ParaDoX a Yahoo! Message
Sorry about that Nikkol, I noticed the error with <% placement on my own and the fact that the stuff in red didn't need to be there- I'm feeling very happy with myself at the moment!

In that case.... everything is working, except for the value staying when all the boxes are empty.

Any ideas how to get around this?

Jamez
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07