Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select unique values from radio button

Status
Not open for further replies.

jennypretty

IS-IT--Management
Apr 13, 2005
45
US
Hello friends:

I tried to create a radio button to get its unique value for each question in SubCat table and store these values in a new table.

How do I fix my code to get its unique value for Report table. For example, when I check on the first Radio for South, then I get a value "1" in the DB Report table. If I check on the second Radio for North, then I get a value of "2" in the DB Report table. Currently, I got values for '0' for all fields. The output will be as below:

Here is my new table for Report:
ReportID CategoryID SubcatID Scale
------------------------------------------
1 01 1 1
2 01 2 2

Category table
CategoryID Category
------------
01 cat
02 cat2
03 cat3

Subcat table
SubcatID Subcat Category_id
-------------------------
1 south 01
2 north 01
3 east 02
4 west 02
5 line 03

ASP Code:
If Request.Form("FormSource") = SubmitForm" Then
sReportID = Request.Form("ReportID")
sCategoryID = Request.Form("CategoryID")
sSubcatID = Request.Form("SubcatID")
sScale = Request.Form("Scale")

SQL = "SET NOCOUNT ON;" &_
INSERT INTO Report (ReportID, CategoryID, SubcatID, Scale) VALUES " &_
"('" & SCategoryID & "', '" & SSubcatID & "', '" & SCategoryID & "', '" & SScale & "');" &_
SELECT @@IDENTITY AS ReportID"
Set objRS = objCon.Execute (SQL)
sReportID = objRS.Fields("ReportID").value
objRS.Close
End If

<form action="" method="post" id="newCategory">
<table>
<tr>
<td>Category and sub</td>
<td>Pass</td>
<td>Fail</td>
<td>NA</td>
</tr>

<%
currCat = ""
sSQL = "SELECT s.*, c.* FROM Category c, Subcat s WHERE s.Subcat_id = c.Subcat_id "
objRS.Open sSQL, objCon
response.Write sSQL
Do Until objRS.EOF
sCategory = objRS("Category")
sSubcat = objRS("Subcat")

if currCat <> sCategory Then
currCat = sCategory
%>
<tr><td><%=sCategory%></td></tr>
<input type="hidden" name="CategoryID" size="40" maxlength="50" value="<%=sCategory%>">
<%
End If
%>
<tr><td><%= sSubcat %></td>
<input type="hidden" name="SubcatID" size="40" maxlength="50" value="<%= sSubcat %>">
<td><input size="20" type="radio" name="<%=sCategory%>" value="1"></td>
<td><input size="20" type="radio" name="<%=sCategory%>" value="2"></td>
<td><input size="20" type="radio" name="<%=sCategory%>" value="3"></td>
</tr>
<%
objRS.MoveNext
Loop

objRS.Close
%>
</table>
<input type="hidden" name="FormSource" value="CatSubmit">
<input type="button" value="Update" onclick="submitForm();">

Thanks so much!
 
What does;

Currently, I got values for '0' for all fields.

Mean??

And if it actually means

"Currently, I got values for '0' for all fields. after pressing submit"

Which radio button(s) is/are checked??

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Hi Chris,
I checked Radio 1, 2 and 3.
I received all '0' for CategoryID, SubcatID and Scale.
It seems like not capture any values from NOT only radio buttons but hidden INPUT as well.
Thanks.
 
HTML forms will pass the values from ALL form elements with the same name attribute as a single comma separated value.

That's how it works, and unchecked radio buttons and checkboxes pass no value

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Chris, how do I fix to pass each unique value for each radio button being checked?
Thanks.
 
Append a number to the name attribute is the simplest is simplest HOWEVER that would 'break' the 'radio button' function of only one being selectable.

The correct way is to NOT reuse the radio button name attribute for any other form element UNLESS you are passing a value from earlier form data in a sequence of inputs to be included in the current form data.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top