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

extracting a value out of a checkbox.

Status
Not open for further replies.

scroce

MIS
Nov 30, 2000
780
US
I wrote this bit of code to set the value of a checkbox called chkAdmin.


dim intChkVal
if Session("admin") = true then

intChkVal="-1"
Response.Write intChkVal
Response.Write &quot;<input type = checkbox id = chkAdmin name = chkAdmin checked value=&quot; & intChkVal & &quot;>&quot;

else
intChkVal=&quot;0&quot;
Response.Write intChkVal
Response.Write (&quot;<input type = checkbox id = chkAdmin name = chkAdmin value=&quot; & intChkVal & &quot;>&quot;)


end if



When the form is submitted, I want to request the value of that checkbox so it is recorded to a yes/no field in my database. I did this via the following code:

Session(&quot;Admin&quot;) = Request.Form (&quot;chkAdmin.value&quot;)


when the form is submitted, I keep getting a data mismatch error b/c the information (0 or -1) is not getting passed into my update sql. It keeps showing as a blank.

I suspect that my logic is ok, but that i have a syntax error somewhere. I can't seem to get it to work - can anyone see where I have gone wrong?

Thanks. How much more water would there be in the ocean if it weren't for sponges?
 
take out the .value, and remove the spaces between the =, and encapsulate in &quot; marks. (i used double, since that's the VB escape sequence for &quot; marks.

eg:
dim intChkVal
if Session(&quot;admin&quot;) = true then

intChkVal=&quot;-1&quot;
Response.Write intChkVal
Response.Write &quot;<input type=&quot;&quot;checkbox&quot;&quot; id=&quot;&quot;chkAdmin&quot;&quot; name=&quot;&quot;chkAdmin&quot;&quot; checked value=&quot;&quot;&quot; & intChkVal & &quot;&quot;&quot;>&quot;

else
intChkVal=&quot;0&quot;
Response.Write intChkVal
Response.Write (&quot;<input type=&quot;&quot;checkbox&quot;&quot; id=&quot;&quot;chkAdmin&quot;&quot; name=&quot;&quot;chkAdmin&quot;&quot; value=&quot;&quot;&quot; & intChkVal & &quot;&quot;&quot;>&quot;)


end if


Session(&quot;Admin&quot;) = Request.Form (&quot;chkAdmin&quot;)

hth
leo leo
 
hmm - for some reason it didn't work. the sql statement being passed in keeps looking like this:

update User set UserName = '1234579', UserFirstName = 'test', UserLastName = 'test', UserEmail = 'test', UserCompany = 'test', UserPassword = '123456', UserZip = '123456', Admin = '', UserPrefix = '', UserPhone = '8834390', UserFax = 'tesa rossa', UserTitle = 'helo', UserAddress = 'my house', UserAddress2 = 'in the mid', UserCity = 'going', UserState = 'ut', AgrmntDate = '4/24/01' where UserID = 264

since admin is a yes/no field I keep getting hit with that data mismatch error. I'm trying to successfully pass a 0 or -1 value back. Dang! any other suggestions?

How much more water would there be in the ocean if it weren't for sponges?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top