Click to See Complete Forum and Search --> : creating table from checkboxes


stevem2004
10-03-2004, 03:04 PM
Hi, I am trying to create a table of input boxes, based on what checkboxes have been ticked.

I have the following code for the checkbox part

<td><input type="checkbox" name="vehicletype" value="carls" id="vehicletype"></td>
<td><input type="checkbox" name="vehicletype" value="car5d" id="vehicletype"></td>
<td><input type="checkbox" name="vehicletype" value="car3d" id="vehicletype"></td>


Then to build the table I am using:-

If vehicletype = carls Then Response.Write"<tr><td class=""normal"">Red Car Single <input type=""text"" name=""redcarls"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Yellow Car Single <input type=""text"" name=""yelcarls"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Green Car Single <input type=""text"" name=""grecarls"" size=""8"" maxlength=""6"" class=""form""></td></tr>" End If
If vehicletype = car5d Then Response.Write"<tr><td class=""normal"">Red Car 5 Day <input type=""text"" name=""redcar5d"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Yellow Car 5 Day <input type=""text"" name=""yelcar5d"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Green Car 5 Day <input type=""text"" name=""grecar5d"" size=""8"" maxlength=""6"" class=""form""></td></tr>" End If

But this does not work properly, no matter what is selected, the table displays all the inputboxes.

Can someone tell me what I am doing wrong? Or am I approaching this the wrong way?


TIA
Steve

chrismartz
10-03-2004, 03:43 PM
Originally posted by stevem2004

If vehicletype = carls Then Response.Write"<tr><td class=""normal"">Red Car Single <input type=""text"" name=""redcarls"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Yellow Car Single <input type=""text"" name=""yelcarls"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Green Car Single <input type=""text"" name=""grecarls"" size=""8"" maxlength=""6"" class=""form""></td></tr>" End If
If vehicletype = car5d Then Response.Write"<tr><td class=""normal"">Red Car 5 Day <input type=""text"" name=""redcar5d"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Yellow Car 5 Day <input type=""text"" name=""yelcar5d"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal"">Green Car 5 Day <input type=""text"" name=""grecar5d"" size=""8"" maxlength=""6"" class=""form""></td></tr>" End If


try....If...Else IF....Else...instead of two If statements! Also, try If car1s = 1 then

stevem2004
10-03-2004, 07:14 PM
Thanks, although the Else If idea didn't work, the second idea did.

I'll just post my findings in case anyone is trying to do the same.

If the checkboxes are written as

<td><input type="checkbox" name="carls" value="1"></td>
<td><input type="checkbox" name="car5d" value="1"></td>
<td><input type="checkbox" name="car3d" value="1"></td>
<td><input type="checkbox" name="car2d" value="1"></td>
<td><input type="checkbox" name="car1d" value="1"></td>


Then I can extract this by doing


If Request.Form("carls") = 1 Then Response.Write"<tr><td class=""normal"">Red Car Single <input type=""text"" name=""redcarls"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal""></td></tr>" End If
If Request.Form("car5d") = 1 Then Response.Write"<tr><td class=""normal"">Red Car 5 Day <input type=""text"" name=""redcar5d"" size=""8"" maxlength=""6"" class=""form""></td><td class=""normal""></td></tr>" End If
etc...

chrismartz
10-03-2004, 09:01 PM
all working then?