PLight 0 Posted June 4, 2018 Report Share Posted June 4, 2018 I have a need for creating checkbox names that go through a loop and are named by concatenating the name of the field with a number that is the loop index. <%if pDiscussed(i) <> "True" then%> <input type="checkbox" name="ynDiscussed" & CStr(i) value="0" /> <%else%> <input type="checkbox" name="ynDiscussed" & CStr(i) value="1" checked /> <%end if%></td> I've done this before with text boxes and there are no problems but somehow with a checkbox it will not work. I've even tried using an array (ynDiscussed[]) along with... <%if pDiscussed(i) <> "True" then%> <input type="checkbox" name="ynDiscussed(" & CStr(i) & ")" value="0" /> <%else%> <input type="checkbox" name="ynDiscussed(" & CStr(i) & ")" value="1" checked /> <%end if%></td> but it doesn't like that either. I can't even substitute in a number instead of the CStr(i) and have it pick it up - my code reading: <input type="checkbox" name="ynDiscussed" & "1" value="0" /> Is this simply impossible or what am I missing? Any help is very much appreciated. Cheers! Quote Link to post Share on other sites
justsomeguy 1,135 Posted June 4, 2018 Report Share Posted June 4, 2018 <input type="checkbox" name="ynDiscussed<%=CStr(i)%>" value="0" /> Quote Link to post Share on other sites
PLight 0 Posted June 5, 2018 Author Report Share Posted June 5, 2018 Hello Justsomeguy Thanks for your reply. I'm afraid it's still not working correctly though when I change it to the following it will work...once through. Then it fails a second time. I realize you don't have my code so it's impossible for you to see what's happening. Here's the current code: <% Do While i < 2 %> <%if pDiscussed(i) <> "True" then%> <input type="checkbox" name="ynDiscussed<%=CStr(i)%>" value="0" /> <%else%> <input type="checkbox" name="ynDiscussed" & <%=CStr(i)%> checked /> <%end if%></td> You will notice that I changed your code a bit by adding an ampersand to the second check. I'm still working on seeing why that would work initially but then fail. It doesn't work if I try to change both of the checks. I'll let you know what I find. Thanks again! Quote Link to post Share on other sites
dsonesuk 913 Posted June 5, 2018 Report Share Posted June 5, 2018 The ampersand can only be used with the server language tags, outside it would be interpreted as just a misplaced text character. You would have to use <%= "ynDiscussed" & CStr(i) %> to concatenate using that method. Is i variable initiated to start as 0? as you will have 2 loops with 0, 1 loop if initial value = 1. Quote Link to post Share on other sites
justsomeguy 1,135 Posted June 5, 2018 Report Share Posted June 5, 2018 You will notice that I changed your code a bit by adding an ampersand to the second check. Well, that's not going to work. If i is set to 2, then you're telling it to write out this HTML: <input type="checkbox" name="ynDiscussed" & 2 checked /> Obviously, the browser doesn't know what to do with that. That ampersand is not valid there, and the 2 is not part of any attribute value. Quote Link to post Share on other sites
webtrickshome 0 Posted July 30, 2018 Report Share Posted July 30, 2018 (edited) use <input type="checkbox" name="ynDiscussed<?=CStr(i)?>"> instead and you are good to go. Edited July 30, 2018 by webtrickshome html special characters Quote Link to post Share on other sites
smus 1 Posted October 19, 2018 Report Share Posted October 19, 2018 On 6/4/2018 at 7:27 AM, PLight said: I have a need for creating checkbox names that go through a loop and are named by concatenating the name of the field with a number that is the loop index. <%if pDiscussed(i) <> "True" then%> <input type="checkbox" name="ynDiscussed" & CStr(i) value="0" /> <%else%> <input type="checkbox" name="ynDiscussed" & CStr(i) value="1" checked /> <%end if%></td> I've done this before with text boxes and there are no problems but somehow with a checkbox it will not work. I've even tried using an array (ynDiscussed[]) along with... <%if pDiscussed(i) <> "True" then%> <input type="checkbox" name="ynDiscussed(" & CStr(i) & ")" value="0" /> <%else%> <input type="checkbox" name="ynDiscussed(" & CStr(i) & ")" value="1" checked /> <%end if%></td> but it doesn't like that either. I can't even substitute in a number instead of the CStr(i) and have it pick it up - my code reading: <input type="checkbox" name="ynDiscussed" & "1" value="0" /> Is this simply impossible or what am I missing? Any help is very much appreciated. Cheers! if pDiscussed is of boolean type, you don't need quotes around the true value. Try checked = "checked" as well What is stored in i variable? Is that (pDiscussed(i)) an array element? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.