Classic ASP checkbox question

asp-classicvbscript

I understand that if the all the inputs being entered as a, b, and c and all the checkbox are checked then the output would look like this.

response.write( request.form("a1") ) = a, b, c
response.write( request.form("chk") ) = 1, 1, 1

Is there a way to determined if the corresponding input text checkbox is checked if not all checkbox are checked?
ie: the input is being entered as a, b, and c then only the corresponding checkbox at "c" is checked.

The output of this will be:

response.write( request.form("a1") ) = a, b, c
response.write( request.form("chk") ) = 1

<form name="myForm">
<input type="text" name="a1" />
<input type="checkbox" name="chk" value="1" />

<input type="text" name="a1" />
<input type="checkbox" name="chk" value="1" />

<input type="text" name="a1" />
<input type="checkbox" name="chk" value="1" />

<input type"submit" value="submit" />
</form>

Best Answer

You're going to need to change the names of your inputs. The only type of input that is intended to have multiple instances sharing a name is a radio button. That is done so you can get the mutually-exclusive select behavior that radio buttons are designed for.

In this case, you're going to want to give each text and checkbox input a different name. So your HTML would look like:

<form name="myForm">
<input type="text" name="a1" />
<input type="checkbox" name="chk1" value="1" />

<input type="text" name="a2" />
<input type="checkbox" name="chk2" value="1" />

<input type="text" name="a3" />
<input type="checkbox" name="chk3" value="1" />

<input type"submit" value="submit" />
</form>

Then simply reference your third checkbox with:

response.write( request.form("chk3") ) 

It would require you to write a little code if you wanted the results to appear in a nice comma delimited list like you've shown, but I would argue that's appropriate.

Related Topic