How do you determine if a radio button is check?
I don't want it to check through javascript like: document.form1.myradiobutton.checked=true;
I want to be able to check it through the server side like when a user click on the radio button, it would submit the form on what has been clicked on and return to the same page.
Sorry if I'm misunderstanding you!
Thanks
Re: How do you determine if a radio button is check?
If I understand your question and you are using classic asp then you will still need to use javascript to submit the form
something like -
Code:
<script type="text/javascript">
function doSubmit(){
var frm=document.myForm;
frm.submit();
}
</script>
<form name="myForm" id="myForm" method="post" action="youraction">
<input type="radio" name="myradiobutton" id="myradiobutton" onclick="doSubmit();"> my radio button text
</form>
Re: How do you determine if a radio button is check?
I want to do something like this, so I can verify what radio button is click on. Use an condition statement within the body tag to determine what to display to the user.
Is there a way to do this?
Code:
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="">
<table width="200">
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="1" onClick="UserType()">
Normal User</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="2" onClick="return UserType()">
Admin Agency</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="RadioGroup1" value="3" onClick="return UserType()">
OverAll Agency</label></td>
</tr>
</table>
</form>
<%if Request(RadioGroup1)=1 then
Response.write(1)
elseif Request(RadioGroup1)=2 then
response.Write(2)
elseif Request(RadioGroup1)=3 then
response.Write(3)
end if%>
</body>
<script language="JavaScript">
function UserType()
{
document.form1.RadioGroup1[0].checked=true;
form1.submit();
return true
}
</script>
</html>
Re: How do you determine if a radio button is check?
Ok, I got it to work now. I forgot to put quotes: Request("RadioGroup1").
Now, how do I maintain the radio button that has been checked?
Re: How do you determine if a radio button is check?
Try something like this -
VB Code:
...
<%
Function IIf(expr,var1,var2)
If expr Then IIf=var1 Else IIf=var2
End Function
Dim rblVal : rblVal=Request.Form("RadioGroup1")
%>
...
<td><label>
<input type="radio" name="RadioGroup1" value="1" onClick="UserType()"[HL="#FFFF00"]<%=IIf(rblVal=1," checked=""checked""","")%>[/HL]>
Normal User</label></td>
</tr>...
Re: How do you determine if a radio button is check?
Yeah, that's what I did. I'm hitting some other problem now. Is there a way to submit just the radio button to get the value rather than the whole page? I still would like to get the value through Request("RadioGroup1") once it is click.
If I submit the whole page, it rerun the whole page, which relate to the query when the page is first started. For example:
Code:
<%if rs("Admin")=11111 then%>
<input type="radio" name="RadioGroup1" value=1>
<%end if%>
Re: How do you determine if a radio button is check?
is it possible to do something like this?
<input type="radio" name="RadioGroup1" value=1 onselect=<%MyValue=Yes%>>
I try it and thought it would work but it didn't.
Re: How do you determine if a radio button is check?
Pretty much the only event you need is "onClick" because with a radio button if it's clicked it's selected you can't click it again to deselect it. Therefore if the onclick event fires on your rbl then one of your options has been selected.
You have to submit the whole page
The easiest way to handle what you're trying to do this is to set a hidden val to true when you submit, then you know that postback is true, then you can ensure your db stuff only gets run when you want it to.
Something like this -
Code:
<%
Dim rblVal : rblVal=Request.Form("RadioGroup1")
Dim bPostback : bPostback=cBool(Val(Request.Form("txtPostback")))
If bPostback=False Then
' Do your first visit To the page stuff here
...
Else
' Do your other stuff here
....
End If
%>
<script type="text/javascript">
function UserType(){
var frm=document.form1;
frm.txtPostback.value=1;
frm.submit();
}
</script>
</head>
<body>
<form name="form1" id="form1" method="post" action="">
<input type="hidden" name="txtPostback" id="txtPostback" value="0">
...
<td><label>
<input type="radio" name="RadioGroup1" value="1" onClick="UserType()"<%=IIf(rblVal=1," checked=""checked""","")%>>
Normal User</label></td>
</tr>...
</form>
...
<%
' VB extender Functions
Function IIf(expr,var1,var2)
If expr Then IIf=var1 Else IIf=var2
End Function
Function Val(vVal)
If IsNumeric(vVal) Then Val=vVal Else Val=0
End Function
%>
Re: How do you determine if a radio button is check?
yeah, but I need to save those data that has been retrieve from the database the first time the user access the page. One thing I noticed about the submit function, is that it create another page of the current page. For example, when you use the BACK button of the browser, it would go back to the same current page until you reach your previous page(different page).
Classic ASP is so complicated. I wish this was ASP.NET but I had no choice on using classic asp.
Re: How do you determine if a radio button is check?
The back button behaviour is correct, you want to go back the same number of pages you've gone forward. You could keep a count of how many postbacks you have and provide your own back link and then call history -<%=iCnt%>
I don't really understand what your problem is why don't you post your page then I can take a look at it and try to work it out.
Re: How do you determine if a radio button is check?
Well, I gone with a different approach and got it to work now. It's not exactly what I want but it is good enough.
Thanks for your help and I did learn something from your coding though.