• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1172
  • Last Modified:

How do I get the value from a radio button and display IT in a report

Hello Everyone,

I have to take the answer from this radio button and place it into a report, but I have no idea how to do that, and if the answer is other, how do I add the textarea value?

Since it's a radio button there will be ONLY one answer, however if they check OTHER, I have to include the textarea, whatever they wrote in it as well...

Can you help me?

Angie


<Input type="radio" name="Opportunity" onClick ="enableOther();" value="1" <%=sOption1Checked%>>The Investor</LI>
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="2" <%=sOption2Checked%>> The Company
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="3" <%=sOption3Checked%>> The Project
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="4" <%=sOption4Checked%>> There Associates
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="5" <%=sOption5Checked%>> All transportation 
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="6" <%=sOption6Checked%>> Other (Please explain)
<BR><textarea id="OpportunityExplanation" name="OpportunityExplanation"><%=sOpportunityExplanation%></textarea>

Open in new window

0
Gemini532
Asked:
Gemini532
  • 7
  • 4
  • 2
4 Solutions
 
inviserCommented:
I have added code before and after the code block you supplied to demonstrate how to retrieve form values. As you can see, the request.form("<your_form_name") function is the way to do this.

Let me know if you need further assistance.

Brian
<% 
if request.form("form_submitted") = "1" then
    response.write "<div>Radio button value: " & request.form("Opportunity") & "</div>"
    
    if request.form("Opportunity") = "6" then
        response.write "<div>Other has been selected. Here is the textarea text<br>"
        response.write request.form("OpportunityExplanation") & "</div>"
    end if
end if
%>
 
<form action="" method="post">
<input type="hidden" name="form_submitted" value="1" />
 
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="1" <%=sOption1Checked%>>The Investor</LI>
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="2" <%=sOption2Checked%>> The Company
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="3" <%=sOption3Checked%>> The Project
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="4" <%=sOption4Checked%>> There Associates
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="5" <%=sOption5Checked%>> All transportation 
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="6" <%=sOption6Checked%>> Other (Please explain)
<BR><textarea id="OpportunityExplanation" name="OpportunityExplanation"><%=sOpportunityExplanation%></textarea>
 
<input type="submit" value="Submit" />
</form>

Open in new window

0
 
Gemini532Author Commented:
request.form("Opportunity")  is NOT working!
I think radio buttons are different. request.form does not work for them in the same way
is this because they are an array?

Can I use JavaScript to display them, becuase when I do request.form("Opportunity") , I don't get any value therefore I cannot make them equal to 1 or 2 all the way through 6...
I do get a value for

response.write sOpportunityExplanation

so the textarea is working, but the radio button IS NOT

CAN U HELP ME?
0
 
hieloCommented:
See code below
<%
Dim opportunity,comments
opportunity = CInt(Request("Opportunity"))
comments = CStr(Request("OpportunityExplanation"))
	
 
If 6<=opportunity  AND opportunity <=1 Then
	Response.Write( "Selected Opportunity: " & opportunity)
	If 6 = opportunity Then
		Response.Write("Comments: "  & comments)
	End If
End If
%>

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Gemini532Author Commented:
This code does not wrok.  It gives me 0 when I  do response.write opportunity

It should give me 6 because that's what hte value in the radio button is... or 5 if it's looking at the radio buttons as arrays... It's difficult to do this question becuase I on't know how to get ddata from aradio button from ASPVBScript, from another page, otherwise, I would just use JavaScript

request.form("opportunity"" goes not seem to  work  It does not give me the value of the radio button, do I have to get this value and place it in a hidden variable and get it from there with request.form?
0
 
hieloCommented:
>> I on't know how to get ddata from aradio button from ASPVBScript
VBScript really does not matter here. You can code your ASP with javascript. That's right, server-side code with javascript:
<%@language="javascript"%>
<%
Response.Write("Value sent for opportunity is: " + Request("Opportunity") );
%>

The server does not know if opportunity was a radio button or any other type of element. So, the fact that it is a radio button also makes no difference. The browser "packs" the data and sends it to the server. The server "unpacks" the sent data and stores it on some server objects from which you can retrieve them.
In this case, Request is the object that will contain your data. You just need to dereference your fields based on the names you supplied on the form.

What does your generated HTML look like? I am not interested in you ASP code, just the HTML code that the browser sees.
0
 
Gemini532Author Commented:
Hi Hielo, your code is no different than any of the code above becuase the value still has to come from


Request("Opportunity")

and that is where the code fails...
Whether I use JavaScript or ASP or whatever, Request("Opportunity") does not give me the value of the radio button            :(


Any idea why radio buttons are different than text buttons, I tried to create a hidden variable  on the same page and place the value in it and then call the value from the second page user request.form("hiddenRadio") but it did not work, I did not konw how to do it, I created a

hiddent intput textbox, and then a JavaScript function, but it doesn't work"

Any ideas why not, or how I can get thsi to work?



<script>
function getHiddenValue(){
	alert(document.OPICForm.Opportunity.value);
	doument.OPICForm.HiddenRadio.value = document.OPICForm.Opportunity.value;
	alert(doument.OPICForm.HiddenRadio.value); 
}
</script>
<input type="hidden" id="HiddenRadio" value="0">

Open in new window

0
 
inviserCommented:
You spelled document as "doument" in several places. That is guaranteed to cause an error.

I would post the entire code for your webpage so we can try to replicate your problem. From what I can see, you should not be having a problem retrieving the value for the radio field. So the answer is likely to be somewhere "outside of the box", so be sure to provide the entire code for you webpage so we can further help you.
0
 
hieloCommented:
>>Any idea why radio buttons are different than text buttons
The browser will not send the value for a radio button that is not checked

>>document.OPICForm.Opportunity.value;
The radio buttons are an array/collection. So, if you want to assign the value of the third radio option to the hidden variable, you would need
doument.OPICForm.HiddenRadio.value = document.OPICForm.Opportunity[2].value;

but, you MUST make sure your form has a name attribute set to OPICForm
<form name="OPICForm"...>
otherwise document.OPICForm evaluates to null and nothing will work as expected because HiddenRadio and Opportunity[2] are children of document.OPICForm, not chidren of null!

save the code below as hielo.asp and submit it. I tested it and it works for me.
<%@language="javascript"%>
<%
var sOptionChecked = new Array("","","","","","","");
sOptionChecked [Request("Opportunity") ] = " checked='checked' ";
var sOpportunityExplanation = Request("OpportunityExplanation") || "";
%>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function enableOther()
{
return true;
}
 
//function getHiddenValue(){
function enableOther(){
	var r = document.getElementsByName("Opportunity");
	for( var i=0, limit= r.length; i < limit; ++i)
	{
		if(r.checked)
			doument.OPICForm.HiddenRadio.value = r.value;
	}
 
}
</script>
 
<form name="OPICForm" action='<%=Request.ServerVariables("SCRIPT_NAME")%>' method="post">
<input type="hidden" id="HiddenRadio" value="0">
<input type="hidden" name="form_submitted" value="1" />
 
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="1" <%=sOptionChecked[1]%> >The Investor</LI>
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="2" <%=sOptionChecked[2]%> > The Company
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="3" <%=sOptionChecked[3]%> > The Project
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="4" <%=sOptionChecked[4]%> > There Associates
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="5" <%=sOptionChecked[5]%> > All transportation 
<br>
<Input type="radio" name="Opportunity" onClick ="enableOther();" value="6" <%=sOptionChecked[6]%> > Other (Please explain)
 
<BR><textarea id="OpportunityExplanation" name="OpportunityExplanation"><%=sOpportunityExplanation%></textarea>
 
<input type="submit" value="Submit" />
</form>
 
 
</body>
</html>

Open in new window

0
 
Gemini532Author Commented:
nothign happens when I click SUBMIT, shoudl I have some of the code in a separate page?
0
 
Gemini532Author Commented:
what is the purpose of  this hidden variable, it is not called from anywhere:

<input type="hidden" id="form_submitted" value="1" />
0
 
Gemini532Author Commented:
I'm getting the following error from the array:
I also noticed this array is written in JavaScript as it ends with a ;   <-------SEMI COLON
 


Microsoft VBScript compilation error '800a0401'

Expected end of statement

/OPICForms/52/52-09.asp, line 62

var sOptionChecked = new Array("","","","","","","");

------------------------------^
0
 
hieloCommented:
>>VBScript
I did not provide vbscript. My example starts with:
<%@language="javascript"%>

Save my example exactly as I supplied it and run it. Once you understand the mechanics behind it, then it's a simple matter of translating it into vbscript if you are more confortable with vbscript. However if you are well versed with javascript and are confortable with it you can write you entire server-side app in javascript.
0
 
Gemini532Author Commented:
Thank you, I figured it out  :)
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now