Click to See Complete Forum and Search --> : How do you pass the value w/dynamic created form w/radio buttons?


bourniqc
06-04-2003, 01:46 PM
I am new to the forum. I am creating a web app for employee/managers to enter performance reviews. In one section, I have Keybehaviors section that is dynamically built from a table based on the company that the employee works for.

The problem that I have is how do you get the value from the radio button, if you assigned the button by a variable. The variable is what is being passed to the next form.

I can not use querystring because of the length limitations. Also, the form is very long and has a lot fields.

I am attaching the code for the dataentry page. (subset of the web app) and the code to view the data.


Cheryl


dataentry.asp
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>data entry-kb</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>

<body>

<form name="dataentry" method="post" action="viewdata2.asp">
<hr width="90%" noshade color="#000000" size="5">
<div align="center"><center><table border="2" width="60%">
<tr bgcolor="#EEFFFF">
<font size="2"><td width="236" height="1"><div align="center"><center><p><strong><font
color="#000080">Key Behavior</font></strong></font></td>
<td width="73" height="1" align="center"><div align="center"><center><p><strong><font
color="#000080">Weight</font></strong></td>
<td width="259" height="1" align="center"><div align="center"><center><p><strong><font
color="#000080">Rating</font></strong></p>
</center></div><div align="center"><center><p><strong><font color="#000080"><small>(Explanation
of Ratings - Click on Key Behavior)</small></font></strong></td>
</tr>
<%


While not rsgetKBinfo.eof
RATING_NAME = RSGETKBINFO("CODE")
CODE_NAME = RSGETKBINFO("CODE_NAME")




%>
<tr align="center">
<td width="254" align="center" valign="top" height="125"><strong><%=code_name%></strong><br>
<font color="#FF0000"><strong>(Required)</strong></font></td>
<td width="75" height="125"><div align="center"><center><p><input type="text"
name="weight" size="3"></td>
<td width="276" height="125" align="center"><div align="left"><p><small><input
type="radio" name="<%=RATING_NAME%>" value="4">4&nbsp; <em><strong>Outstanding Performer</strong></em></small></p>
</div><div align="left"><p><small><input type="radio" name="<%=RATING_NAME%>" value="3">3&nbsp;
<em><strong>High Performer</strong></em></small></p>
</div><div align="left"><p><small><input type="radio" name="<%=RATING_NAME%>" value="2">2&nbsp;
<em><strong>Proficient</strong></em></small></p>
</div><div align="left"><p><small><input type="radio" name="<%=RATING_NAME%>" value="1">1 <strong><em>&nbsp;
Needs Improvement</em></strong></small></td>
</tr>
<%

rsgetKBinfo.movenext
wend
%>
</table>
</center></div><div align="center"><div align="center"><center><table border="0"
width="90%">
<tr align="middle">
<td width="50%" colspan="2"><div align="center"><center><p><strong>REVIEW STATUS </strong></td>
</tr>
<tr align="center">
<td width="36%"><div align="left"></div></td>
<td width="64%" align="left"><input type="radio" value="WIP" name="reviewstatus">Work in
Progress </td>
</tr>
<tr align="center">
<td width="36%"></td>
<td width="64%" align="left"><input type="radio" value="TEMP" name="reviewstatus">Template
</td>
</tr>
<tr align="center">
<td width="36%"></td>
<td width="64%" align="left"><input type="radio" value="COMP" name="reviewstatus" checked>Complete
(Calculate)</td>
</tr>
</table>
</center></div><div align="center">
<dd align="center">&nbsp;</dd>
<dd align="center">&nbsp;</dd>
<dd align="center"><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"> </dd>
</div><%
response.write ("<input type=""hidden"" name=""RATING_NAME"" value=")
response.write chr(34)
response.write RATING_NAME
response.write chr(34)
response.write ">"

%>
</div>
</form>
</body>
</html>




viewdata2.asp
<html>

<head>
<title></title>
</head>

<body>

<p align="LEFT"><font size="3"><a href="<%=INSTRUCTIONS%>">Instructions</a> on how to fill
this form</font><b><font size="5" color="#000080"> </p>
</font>

<p ALIGN="CENTER"><font size="5" color="#000080"><%=TITLE%> </p>

<p align="center"><font size="5" color="#000080"><br>
Management/Exempt<br>
Performance Management Plan and Assessment </font></p>

<form method="POST" action="postdata.asp" align="center"
onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1">
</font><dl>
<dd align="center"><%=MINDESCRIPTION1%>
</dd>
<dl>
<dd align="center"></b><b>&nbsp;</dd>
<dd align="center"></b><b>&nbsp;</dd>
<dd align="center"><div align="center"><hr width="90%" noshade color="#000000" size="5"
align="center">
<div align="center"><center><table border="1" height="66" width="90%">
<tr bgcolor="#EEFFFF">
<font size="5" color="#000000"><strong><td height="60"></strong><font size="4"
color="#000000"><a name="kba">III. KEY BEHAVIOR ASSESSMENT:</a></font><font
color="#000080" face=" serif" size="3"><p><%=kb_DESCRIPTION1%></p>
<p><%=kbDESCRIPTION1%></p>
<p><%=kbDESCRIPTION2%></font> </p>
<p><font color="#000080" size="3"><a href="<%=INSTRUCTIONS%>">Click here for help</a></font></font></td>
</tr>
</table>
</center></div><div align="center"><center><p><%=kbdescription3%></p>
</center></div><div align="center"><center><table border="2" width="60%">
<tr bgcolor="#EEFFFF">
<font size="2"><td width="236" height="1"><div align="center"><center><p><strong><font
color="#000080">Key Behavior</font></strong></font></td>
<td width="73" height="1" align="center"><div align="center"><center><p><strong><font
color="#000080">Weight</font></strong></td>
<td width="259" height="1" align="center"><div align="center"><center><p><strong><font
color="#000080">Rating</font></strong></td>
<td width="259" height="1" align="center"><div align="center"><center><p><strong><font
color="#000080">Score </font></strong></p>
</center></div><div align="center"><center><p><small><strong><font color="#000080">(Weight
x Rating)</font></strong></small></td>
</tr>
<tr align="center">
<%
While not rsgetKBinfo.eof


CODE_NAME = RSGETKBINFO("CODE_NAME")

DIM KB_WEIGHT_STRING
DIM KB_WEIGHT_ARRAY
DIM KB_WEIGHT_COUNTER
KB_WEIGHT_STRING = WEIGHT
KB_WEIGHT_ARRAY = SPLIT(KB_WEIGHT_STRING,",")

%>
</tr>
<tr align="center">
<td width="254" align="center" valign="top" height="125"><strong><%=CODE_NAME%></strong><br>
<font color="#FF0000"><strong>(Required)</strong></font></td>
<td width="75" height="125"><div align="center"><center><p><font face="Times New Roman"
size="3" color="#0000FF"><%=KB_WEIGHT_ARRAY(KB_WEIGHT_COUNTER)%> % </font></td>
<td align="center" bgcolor="#FFFFFF" width="78"><%=rating_name%>
</td>
<% KB_WEIGHT_COUNTER = KB_WEIGHT_COUNTER +1
rsgetkbinfo.movenext
wend
%>
<td align="center" bgcolor="#FFFFFF" width="78">&nbsp;</td>
</tr>
</table>
</center></div><div align="center"><center><p><font color="#000000"><big><big><%=mgr_description%></big></big></font></p>
</center></div><div align="center"><center><p>&nbsp;</p>
</center></div></div></dd>
<div align="center"><center>
<dt>&nbsp;</dt>
</center></div>
<dd align="center"><div align="center"><center><table border="1" width="30%">
<tr>
<td align="left"><input type="radio" value="WIP" name="reviewstatus"
<%response.write WIPSTATUS%>>Work in Progress </td>
</tr>
<tr>
<td align="left"><input type="radio" name="reviewstatus" value="COMP"
<%response.write CALCSTATUS%>>Completed </td>
</tr>
<tr>
<td align="left"><input type="radio" name="reviewstatus" value="TEMP"
<%response.write TEMPSTATUS%>>Template &nbsp; (Enter Template Name)&nbsp; <input
type="text" name="strTemplateName" size="30"></td>
</tr>
</table>
</center></div></dd>
<dd align="center">&nbsp;</dd>
<dd align="center"><div align="center"><center><p><input type="submit" value="Submit"
name="B1"><input type="reset" value="Reset" name="B2"> </p>
</center></div></dd>
</dl>
<%

%>
</dl>
</form>
</b>
</body>
</html>

khaki
06-04-2003, 02:20 PM
hi Cheryl...

I think that all you need to do is add a text box and populate it with the same value as you are naming the radio buttons:

<input type="hidden" value=<%=RATING_NAME%> name="passVal">

and then on viewdata2.asp you can obtain that value by using the known name of the textbox:

newVar = Request.Form("passVal")

did I understand the problem correctly?

;) k

Ribeyed
06-04-2003, 02:43 PM
hi,
you don't have to know the names of the form elements you are requesting, you can use the following:



<%
for each item in request.form
response.write item & " = " & request.form(item)
next
%>


Hope this helps

khaki
06-04-2003, 02:54 PM
hi Dave...

but how would you isolate 1 item out of the form for use within the new page if you don't know the name/value?

I don't see how that does anything other than just list all of the form's values.

I didn't really poke through her code...
but I beleieve that she needs to pass them to the new page in order to use them.... not just list them.

or did I really misunderstand the original question?

;) k

khaki
06-04-2003, 03:24 PM
:eek: :eek: p s

i mis-read Dave's answer.

yeah... that works fine.
sorry :rolleyes:

;) k

EDIT:
oh... but wait....
No... I was right.
She doesn't know the value of the variable.... so the NAME of the variable would not be known either.

You need to give the value a name that you can refer to.

I don't think that it can be done by listing all the variables.

(wow... now I'm confusing myself :rolleyes: )

Ribeyed
06-04-2003, 04:20 PM
Hi khaki,
you can use various methods to isolate each item. Take for example a dynamically generated form. You want to display a list/menu box for every record in a table from you database. Your form can end up with 3 list/menu boxes or 10 list/menu boxes. Or you are using radio buttons but the number of radio options is detemined by the amount of records so you may have a radio option that sometimes has 3 answers or can be 5 answers.
On your page you will have something like this:

<%
recordcount = 1
while not RS.EOF
field = RS(0)
%>
<select name="select<%=recordcount%>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<%
recordcount = recordcount + 1
RS.MoveNext
Wend

%>
<input name="recordcount" type="hidden" value="<%=recordcount%>">


So each select in the loop gets a different name.

Now you don't know how many there can be so if you use the code i posted.
Ok as i said depending on what you need would depend on how to handle the next page coding.
You can then do something like this:

<%
recordcount = request.form("recordcount")
for each item in request.form
Theitem = Left(item, 6)
if Theitem = "select" then
selectID = Right(item, 1)
response.write "form element " & SelectID
'basically you can run any code you need here
end If

response.write item & " = " & request.form(item)
next
%>



Hope this helps

khaki
06-04-2003, 04:38 PM
I don't think that we are seeing it the same way Dave.

How is the 2nd page supposed to be able to use a variable if the name of the variable was dynamically created in the 1st page.

In other words... how does the 2nd page know what it's called?
The way you have it... the name is the same as the value.
But the 2nd page doesn't know the name OR the value....

that's why you need to create a static name and populate it with the value.

That's the way I see it.

But...
we're not hearing any feedback from Cheryl anyway.... so....
whatever :rolleyes:
;) k

bourniqc
06-04-2003, 05:16 PM
I am working on the solutions that you have posted. The for each item in request.form seems like that will work for me. Once I have it coded and working the way I like, I will post the solution.

Thanks to all for your help.
Cheryl

Ribeyed
06-04-2003, 05:44 PM
Hi Khaki,

bourniqc
I have Keybehaviors section that is dynamically built from a table based on the company that the employee works for.

The problem that I have is how do you get the value from the radio button, if you assigned the button by a variable. The variable is what is being passed to the next form.


The way I see the problem is that bourniqc has a form with a dynamic number of groups of radio buttons. The amount of buttons in the radio group is static.
Each group needs a different name, but one that identifies it from the other groups for this bourniqc is using <%=RATING_NAME%>.

You are correct in saying :


but how would you isolate 1 item out of the form for use within the new page if you don't know the name/value?
[quote]

Also because the number groups of radio buttons that could be, depending on how many records are returned, this is a problem.

[quote]
How is the 2nd page supposed to be able to use a variable if the name of the variable was dynamically created in the 1st page.


Using the loop and request.form(item) would retrieve the name and value of all the form elements submitted.


In other words... how does the 2nd page know what it's called?


It is called “item”
Item in this case refers to both name and value. “Item” on its own will retrieve the name of the form element and “request.form(item)” will retrieve the value.

Now if the form has other elements apart from the radio buttons bourniqc may have to somehow retain whether the element was a radio button or a textbox etc.
When I put “select” in the name it was for that purpose.


The way you have it... the name is the same as the value.


This is not the case “item” is a VBScript reserved word and refers to both name and value.

khaki
06-05-2003, 11:05 PM
okay...
so either I learn something here...
or we address the issue at hand as it appears to exist in the original question (as far as I'm concerned)...

there are actually 4 form elements that get passed to the 2nd page.

so... being able to identify them (for use in the 2nd page) seems logical (to me).

and oddly enough (after looking at the source code more closely)... there is actually a form element named "rating_name" which is actually a hidden text box (and where have I heard that idea before?)...

but... even more oddly... it has NO value assigned to it.
So.... if we follow my original suggestion...
you just assign the value of <% =rating_name%> to that text box...
and the issue is resolved.

otherwise...
can I please see a working example of how the request.form(item) would be used in this particular instance?

I happen to know that my suggested solution works....
so if there is another solution (especially a better one)...
I would definitely like to know how to implement it.

is there some working source code (as it applies to this question) that we can see....
because I still don't get it :rolleyes:

just trying to learn... so can we apply everything to this example? ...
;) k

Ribeyed
06-12-2003, 09:45 PM
Hi khaki,

sorry never replied to your post.

otherwise...
can I please see a working example of how the request.form(item) would be used in this particular instance?

Couldn't just make something up on the spot but the code i created for the bellow thread uses the code i posted for this thread to achieve the same thing. Hope this helps you.

http://forums.webdeveloper.com/showthread.php?s=&postid=58606#post58606