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!

checkboxes - Using asp to write html

Status
Not open for further replies.

scroce

MIS
Nov 30, 2000
780
US
I'm working on an asp site that has some code that apparently generates html, but I don't understand how it does it. I have used response.write to generate html before, but this looks different. See below example:

Response.Write (&quot; <TR>&quot;)
Response.Write ( Label(&quot;Zip Code&quot;, COLUMN1WIDTH))
Response.Write (&quot; <TD>&quot;)
Response.Write ( Textbox(&quot;UserZip&quot;, Session(&quot;UserZip&quot;), 10, Session(&quot;DisplayMode&quot;), 10))
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; </TR>&quot;)
Response.Write (&quot; <TR>&quot;)
Response.Write ( Label(&quot;Admin?&quot;, COLUMN1WIDTH))
Response.Write (&quot; <TD>&quot;)
Response.Write ( Textbox(&quot;Admin&quot;, Session(&quot;Admin&quot;), 10, Session(&quot;DisplayMode&quot;), 10))
' Response.Write &quot;<INPUT type=checkbox disabled=true name=Admin value=&quot; & Session(&quot;Admin&quot;) & &quot;>&quot; THIS IS A FAILED FIX ATTEMPT
Response.Write (&quot; </TD>&quot;)
Response.Write (&quot; </TR>&quot;)


In particular, I don't understand this line:

Response.Write ( Textbox(&quot;Admin&quot;, Session(&quot;Admin&quot;), 10, Session(&quot;DisplayMode&quot;), 10))

1. the &quot;admin&quot; field is a yes/no field in my access database. I need it to be a check box on my form. I tried changing &quot;Textbox&quot; to &quot;Checkbox&quot; but it doesn't recognize it. How do you get a checkbox to work in asp?

2. I have never seen a textbox generated by html without <input> tags. How is this happening and what do the 10's mean? I'm guessing the might be field lengths, but I don't understand the syntax and can't seem to find anything similar in my wrox book. I'm having no luck being able to change the text box to a check box.

Can anyone help me?

How much more water would there be in the ocean if it weren't for sponges?
 
you sure it isnt

1) a Design time control by Microsoft's Scriptiong classes (usally under the _ScriptLibrary, and usally something I dont use)

2) Response.write will return whatever the TextBox() function returns, as a result, you may create a simple function like this below

Code:
  Function Textbox(name, width, defaulttext)
     TextBox = &quot;<input type=&quot;&quot;text&quot;&quot; width=&quot; & width & &quot; name =&quot;&quot;&quot; & name & &quot;&quot;&quot; value=&quot;&quot;&quot; & defaulttext & &quot;&quot;&quot;>&quot;
  End function

As a result if you were to do

Response.write TextBox(&quot;neat&quot;, 20, &quot;something here&quot;)

on the page you will see

<input type=&quot;text&quot; width=20 name=&quot;neat&quot; value=&quot;something here&quot;>

check your includes at the top maybe one of them point to one of the Scripting Libraries that can create textboxes like I showed. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Thanks KB!!

ok - your example Response.write TextBox(&quot;neat&quot;, 20, &quot;something here&quot;) makes a little more sense - it kind of looks like what the previous programmer was doing.

Good call - on further analysis, your assessment #2 was correct. the textbox function was defined by the previous programmer in a separate asp file that was included at the top of the page.

Kudos to you. That answers half of my headache.

The other half has to do with getting checkboxes to work with this yes/no field called &quot;admin&quot;. I want the user at the web site to be able to choose whether or not that particluar record he is viewing has admin status by clicking a checkbox on or off. When the form is submitted, I want the field in the database to be updated accordingly.

This must be a fairly easy and common task to perform. Can you give me or point me towards some sample code for this?


How much more water would there be in the ocean if it weren't for sponges?
 
in usual HTML, the check box is usally turned on by saying Checked (or checked=on =off)

an example

<input type=&quot;checkbox&quot; checked ...>
so it may not reconize your yes/no , does the source of the HTML come back correctly, but just not behaving correctly?

you may have to setup an if/then statement to see what the admin value is, then to do your stuff according to what it is, rather than a direct pass over. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
bingo - it is not behaving correctly - it keeps saying &quot;data type mismatch&quot; every time the form is submitted. right now I have it showing up as a text box. The value in the text box shows &quot;True&quot; and &quot;False&quot;, but when you update the form, if you actually type true or false in there, it will say &quot;data type mismatch&quot; - However, the values &quot;0&quot; and &quot;-1&quot; will work correctly.


I tried to address it using the following code&quot;
Response.Write &quot;<INPUT type=checkbox name=Admin value=&quot; & Session(&quot;Admin&quot;) & &quot;>&quot;

and it wasn't working. I believe the error was that &quot;data type mismatch&quot; again.

I think you are on the right track of your assessment of the solution. Do you know of any code examples on the web or in the wrox book?


How much more water would there be in the ocean if it weren't for sponges?
 
if you know that session(&quot;Admin&quot;) is a boolean type why not do

Code:
if Session(&quot;Admin&quot;) = True then
  checked = &quot;checked&quot;
else
  checked = &quot;&quot;
end if

Response.write &quot;<input type=&quot;&quot;checkbox&quot;&quot; name=&quot;&quot;Admin&quot;&quot; &quot; & checked & &quot;>&quot;
Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
OK - that worked The check box now reflects the yes/no state of the data source. So now, using that rationale I need to be able to write the state of the check box on the website back to the database if there is a change. I've tried to do it this way:

Dim boolChecked
Dim intCheckedValue
If Session(&quot;Admin&quot;) = True then
boolChecked = &quot;checked&quot;
intCheckedValue = -1
Else
boolChecked = &quot;&quot;
intCheckedValue = 0
End If

Response.Write &quot;<INPUT type=checkbox name=chkAdmin &quot;& boolChecked &&quot; value =&quot;& intCheckedValue &&quot;>&quot;

when I response.write the sql so I can see what is happening, I find that no value is being passed to the admin field, when it should be 0 or -1. I think this is why I am getting an ODBC syntax error. Can you see where I have a syntax error above? I've tried a few permutations already but I guess I just haven't hit on it. 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