Retaining Radio Button Value

Results 1 to 2 of 2

Thread: Retaining Radio Button Value

  1. #1
    Join Date
    Dec 1969

    Default Retaining Radio Button Value

    I have an asp page with three radio button, grouped together by the name attribute. The problem I have is, I want to keep the selected radio button checked when the form is submitted - currently, if I set the checked attribute for say the first button and the user clicks the third button, when the form is submitted and redisplayed, the checked radio button has reverted back to the first one - how do I keep the third button checked?

  2. #2
    Join Date
    Dec 1969

    Default RE: Retaining Radio Button Value

    If the action of the form is to submit itself (the same asp page), then you could declare a variable and do logic on that variable to determine which button was checked. <BR>&#060;%<BR>Dim sIsChecked<BR>sIsChecked = Request.Form("put your radio name here") <BR>-- The above will give the value to the radio button that was selected. <BR>--You can then declare another variable which will be the variable that dynamically writes "SELECTED" inside the radio html tag that was selected.<BR>eg. <BR>Dim sSelected1, sSelected2, sSelected3<BR>Select Case sIsChecked <BR> Case 1<BR> sSelected1 = "SELECTED" <BR> sSelected2 = ""<BR> sSelected3 = "" <BR> <BR> Case 2<BR> sSelected1 = "" <BR> sSelected2 = "SELECTED"<BR> sSelected3 = "" <BR> Case 3<BR> sSelected1 = "" <BR> sSelected2 = ""<BR> sSelected3 = "SELECTED" <BR> End Select<BR><BR>%&#062;<BR>-- Then inside your HTML tags, write these vbScript variables <BR>&#060;INPUT TYPE=radio Name=Whatever Value=1 &#060;%=sSelected1%&#062;&#062;<BR>&#060;INPUT TYPE=radio Name=Whatever Value=2 &#060;%=sSelected2%&#062;&#062;<BR>&#060;INPUT TYPE=radio Name=Whatever Value=3 &#060;%=sSelected3%&#062;&#062;<BR><BR>--This way if it was selected before, it will now have "SELECTED" written inside its tag, otherwise, the variable above will be an empty string, and it will not be checked. <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts