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!

Checkbox question

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
Hi there,

In the following code, how can I show the checkbox is checked if there is a value in the field? Is it even possible? If the user goes back to edit other text boxes, and forgets to check this one again, it will erase what's in the database table already....


<INPUT TYPE=CHECKBOX NAME=&quot;&quot;&quot; & _
iCount & &quot;.notes&quot;&quot; VALUE=&quot;&quot;&quot; & _
&quot;*&quot; & &quot;&quot;&quot;>&quot;

Any thoughts or suggestions would be greatly appreciated. Ttanks in advance.

Mel

 
I'm not totally sure I know what you mean. Are you talking about detecting if the checkbox is checked on the client side? or detecting it on the server side?

On the server side, when you submit the form to an ASP page, simply request the form element. If there is only one checkbox, you'll just receive the value (if it is checked, or nothing if it's not checked). If there are multiple checkboxes with the same name, it'll give you them in a list using a comma as the delimiter.

If you want it on the client side, use javascript to detect the form element value.

If you are confused on any of this, or are asking a different question, please ask again in a different manner. ;-)
-Ovatvvon :-Q
 
Hi Ovatvvon,

Thanks so much for your reply. Let me try to make it more clear. If the user has checked the box before, an * posts to a SQL table. The problem is, they have an option to go back and change information and the checkbox is blank. If there is a value in that field, and they forget to check it again, it posts a null value. So if it's check already, all is well. Does that make sense? I don't work with checkboxes too much so I don't have a clue. Would a radio button work better? Thanks again.

 
Are you asking how to make it automatically checked without the user physically checking it? Or how to make it detect that it was checked upon the user going back to the page?

If all you need is for it to be auto-checked, then your code can be as such:

<input type='checkbox' name='myName' value='someValue' CHECKED>

that will auto insert a check in the box and if the user doesn't want the value in there, they will have to physically have to check the box to remove the check.

Now, if you only want the check to be auto inserted upon the user returning to the page when they had it upon the initial submit of the page, simply insert an IF statement to decide if the check was in there last time...if so, then insert the checked command:

<%
Dim wasChecked
wasChecked = Request.Form(&quot;wasChecked&quot;)

Response.write(&quot;<input type='checkbox' name='myName' value='someValue'&quot;)

If wasChecked = true Then
Response.write(&quot; CHECKED&quot;)
End If

Response.write(&quot;>&quot;)
%>

Hope this helps a little more...let me know.
-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top