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

Session variable does not work on checkbox?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I have this program with my ASP form page. When I used the session variable with other input controls such as Text, Select, it worked fine. But it did not work on Checkbox. It can not pass the value to the database backend. I would like to know why.
<TD><INPUT type=&quot;text&quot; id=text3 name=DOB VALUE=&quot;<%= session(&quot;DOB&quot;)%>&quot;></TD> It works fine.

<TD><INPUT type=&quot;checkbox&quot; id=checkbox3 name=AotherProcedure VALUE=&quot;<%= session(&quot;AnotherProcedure&quot;)%></TD> it does not work.
When change it to
<TD><INPUT type=&quot;checkbox&quot; id=checkbox3 name=AotherProcedure VALUE= NO></TD>
It worked.

Haijun





 
longmatch,


<INPUT type=&quot;checkbox&quot; id=checkbox3 name=AotherProcedure checked>

This works with no quote marks.

fengshui_1998

 
I am sorry I did not state my question more clearly. What I need to know is why the session variable does not work on Checkbox control? I used the YES/NO instead of Checked in my real program, it worked well.

Haijun
 
There is a difference between the VALUE of a checkbox and whether it is CHECKED or not. You see a checkbox can have any value under the sun. It can be a number, a name, a whole sentence (within &quot;quote marks&quot;). But the VALUE is meaningless without the CHECKED property.

When the form with the checkbox is submitted, the NAME of the checkbox will be sent. If the checkbox is CHECKED, then the value of the checkbox is sent as well. Here's a simple example:
Code:
<input type=checkbox name=checkbox1 value=&quot;ONE&quot;>
checkbox not CHECKED
then the form sends:
Code:
checkbox1=

checkbox is CHECKED
then the form sends:
Code:
checkbox1=ONE

I believe that you are wanting to control if the default value of the checkbox is CHECKED when the page loads. To do this you need an if statement to write the CHECKED if the value of a variable is some specific value.

If this is what you want, reply to this post, and I will get the code I have used (I don't have it on me currently). Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Dear Einstein47:
Your explanation cleard my misunderstanding about the checkbox. In my program, I want to send the data to my Access database, the datatype for this item is YES/NO. I used
<TD><INPUT type=&quot;checkbox&quot; id=checkbox3 name=AnotherProcedure VALUE=&quot;<%= session(&quot;AnotherProcedure&quot;)%></TD>

It could not send anything to the database, no matter I checked or unchecked this checkbox. Then I used
<TD><INPUT type=&quot;checkbox&quot; id=checkbox3 name=AotherProcedure VALUE= NO></TD> to replace the last one, it worked well.

How can I use the session variable on Checkbox? Are there any difference using session variable from regular variable?

Thank you

Haijun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top