0

I have a form with 3 text fields and 3 checkboxes. I had implemented VB Script validation so if a user submits the form and leaves something empty, the user will get back to the form WHILE having the fields filled in already. That said, this is not working for the chackboxes.

this is the code I am using for the checkboxes I am doing code in the value""

<input type="checkbox" name="ClaimSection_ActivityProof"  id="ClaimSection_ActivityProof"  value="<%=Request.Form("ClaimSection_ActivityProof")%>" style="width:20px" />
<input type="checkbox" name="ClaimSection_InvoicesPayableByPartner" id="ClaimSection_InvoicesPayableByPartner" value="<%=Request.Form("ClaimSection_InvoicesPayableByPartner")%>"  style="width:20px" />
<input type="checkbox" name="ClaimSection_InvoicesPayableByGFI" id="ClaimSection_InvoicesPayable" value="<%=Request.Form("ClaimSection_InvoicesPayable")%>" style="width:20px" />

To cut the sotry short, if a user checks 2 checkboxes, submits the form, and when he is redirected back to the form again, the checkboxes will remain checked. How I can do this please?

2
  • Is JavaScript just not allowed? Commented Mar 26, 2012 at 12:35
  • no JS. I can use only vb script. Commented Mar 26, 2012 at 12:47

3 Answers 3

1

name ( or group ) the checkboxes by the same name, ( I assume they all are related ClaimSection matter) So ,you can name them all as "ClaimSection". Just make sure you assign each one its own unique values!

Example;

<input type='checkbox' name='ClaimSection' value='ActivityProof'>
<input type='checkbox' name='ClaimSection' value='InvoicesPayableByPartner'>
<input type='checkbox' name='ClaimSection' value='InvoicesPayableByGFI'> 

With this naming, if your user checks more than 2 checkboxes, you will get the corresponding values in a comma separated fashion. So, if your user checks the last 2 checkboxes, you will get "InvoicesPayableByPartner,InvoicesPayableByGFI" in return.

Now that you know this, it won't be hard to set up a bunch of if branches to handle the checked vs not checked matter by comparing against what you got in the request("ClaimSection")

Something like the following can get you in the right direction..

dim submitted_ClaimSections 
submitted_ClaimSections = request("ClaimSection") 
submitted_ClaimSections = "," & submitted_ClaimSections & ","

//handle the ActivityProof checkbox checked_or_not ="" 
if  instr(submitted_ClaimSections,"," & "ActivityProof" & ",")>0 then       
    checked_or_not = "checked" 
end if 
Response.write "<input type='checkbox' name='ClaimSection' value='ActivityProof' " & checked_or_not & "> ActivityProof" 

//handle the InvoicesPayableByPartner checkbox checked_or_not ="" 
if instr(submitted_ClaimSections,"," & "InvoicesPayableByPartner" & ",")>0 then     
    checked_or_not = "checked" 
end if 
Response.write "<input type='checkbox' name='ClaimSection' value='InvoicesPayableByPartner' " & checked_or_not & "> InvoicesPayableByPartner" 


//handle the InvoicesPayableByGFI checkbox checked_or_not ="" 
if instr(submitted_ClaimSections,"," & "InvoicesPayableByGFI" & ",")>0 then
    checked_or_not = "checked" 
end if 
Response.write "<input type='checkbox' name='ClaimSection' value='InvoicesPayableByGFI' " & checked_or_not & "> InvoicesPayableByGFI"
Sign up to request clarification or add additional context in comments.

Comments

1

I think you should post back your form data. Try following links:

http://www.motobit.com/tips/detpg_post-binary-data-url/

http://www.tek-tips.com/viewthread.cfm?qid=1281365

These links provides some example code sending form data with post method. Unfortunatly I haven't set up an IIS, so I couldn't try those examples. At the first view the idea can work.

Comments

1

The value attribute is not really relevent to making sure the checboxes retain their checked state on load / postback.

To do this, you need to check if they where checked on submit ("on" in request.form), if "on" then set checked="checked".

Example:

<%

if len(request.form("ClaimSection_ActivityProof")) > 0 then
    ClaimSection_ActivityProof_Checked = " checked=""checked"""
else
    ClaimSection_ActivityProof_Checked = ""
end if

%>

<input type="checkbox" name="ClaimSection_ActivityProof"  id="ClaimSection_ActivityProof" <%=ClaimSection_ActivityProof_Checked %> style="width:20px" />

Hope that makes sense.

J.

4 Comments

Almost there :) the only problem is that when I am implimenting this code, the checkboxes are showing as checked when I visit the page for the first time. They must be unchecked at first.
Hmm, that is strange, try my revised code (note the use of len() and the empty string if len = 0)
One last question.. your method works but because it is a group of checkboxes it is not working. xample: i select 1 checkbox from the group. then I submit while leaving a textbox left empty. When I get back to the form, ALL the group of checkboxes are checked.... :/
That would imply all your checkboxes have the same name attribute (as per John Smiths answer) but your opening question shows each checkbox as having a unique name? My method only works for uniquely names checkboxes - try Johns answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.