Jump to content
PLight

Creating Dynamic Checkbox Names

Recommended Posts

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!

Share this post


Link to post
Share on other sites

This does not seem to be an HTML question, it looks like ASP. This syntax is not familiar to me, but if I had to guess what's wrong, I'd say you need to wrap the "CStr" part in <% %> tags.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...