views:

188

answers:

2

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>
+7  A: 

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.

Paul
Thats the way to do it, right tool for the right job + 1
Pete Duncanson
Thanks. I was hoping there is another alternate.
nolabel
A: 

If reason you want a comma-delimited string similar to "a, b, c" you could change the values of all your checkboxes to "1", "2", "3" instead of all being "1".

mike nelson