Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2012, 06:50 AM
Registered User
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Keep radio button status - arrrrhhhh!

These radio buttons are driving me mad!

I'm trying to keep the 'state' of the selected radio button on post back, but it's nto working!!

here is my code:

Code:
 
(rsOfferID  <% Response.Write (RSOffersRest.Fields.Item("OfferID").Value)%> ) - 
  (session offerid <%Response.Write Session("OfferID")%>)
</div>  
<div id="radios">
<% If Session("OfferID")=(RSOffersRest.Fields.Item("OfferID").Value)  Then%>
<input name="offerselect" type="radio" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" checked="checked" />yes
<% Else%>
 <input name="offerselect" type="radio" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" />
 no
 <% End If %>
grrrr
Andy
 
Old June 27th, 2012, 06:53 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Hey Andy

A couple of observations if I may. IMO there is a much better and simpler way to achieve this. I see you are using session variables, there is no need to use a session variable in this situation. For many reasons you should only ever use them as a last resort. On a side note use form variables and querystrings always before sessions variables. I would simply do this to make sure the correct checkbox was checked when the form is posted:
Code:
 <input type="radio" name="offerselect" value="1" <% if trim(request.form("offerselect")) = "1" then response.write  " checked " end if %>>yes
 <input type="radio" name="offerselect" value="0" <% if trim(request.form("offerselect")) = "0" then response.write  " checked " end if %>>No
Please note - Its good practice when capturing Yes/No answers to store a No as 0 and a Yes as 1 and post into a table field that is a bool (True/False) data type. This is a good idea for all sorts of reasons - hence the reason I have place value="1" for Yes and value="0" for no. Of course you can easily chnage this if you must. Out of interest what possible values could present in this DB value?

value="<%=(RSOffersRest.Fields.Item("OfferID").Val ue)%>"
__________________
Wind is your friend
Matt
 
Old June 27th, 2012, 06:58 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

But if you must get your method going you need to compare both of these values:

Code:
If Session("OfferID")=(RSOffersRest.Fields.Item("OfferID").Value)  Then
if they are the same and it still not fireing you should make sure they are the same type EG use cint(Session("OfferID"))

Also you have this in your else:
Code:
<input name="offerselect" type="radio" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" />
well this is never going to be checked becasue there is no "checked" anywhere
__________________
Wind is your friend
Matt
 
Old June 28th, 2012, 03:50 AM
Registered User
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys

mat41 i'm using session variables because i am taking the value of the radio button to filter the recordset. This then changes the offer for that particular product.
Then on the post back i compare the session offerid to each offer in the radio button group.
I then use an IF statement to find the offerid that equals the session offerid and add the 'checked' if they match.

lol but it's not working grrrr

Thanks
Andy
 
Old June 28th, 2012, 06:59 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Hi Andy

;;;mat41 i'm using session variables because i am taking the value of the radio button to filter the records

FYI When you submit a form and need to use the radio button value for what ever reason you should always use the request object. There is no reason/need to use session variables and there are many reasons why they should only ever be considered last resort. Its simply lazy and a bad practice....You should consider retrieving values in this order:

Request.form("offerID")
Request.querystring("offerID")
Session("offerID")

As you get more experienced you will stop using session variables. You should have a read up on all the reasons why they should be used as a last resort. Anyhow enough of that....

;;;Then on the post back i compare the session offerid to each offer in the radio button group

When you say radio button group, are there more than two radio button on your page named offerGroup? can you post the HTML source of your problematic code? I would liek to see what the value is in: Session("OfferID"), RSOffersRest.Fields.Item("OfferID").Value and you <input name="offerselect"....
__________________
Wind is your friend
Matt
 
Old June 29th, 2012, 05:19 AM
Registered User
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi mat41

you're quite right regarding the use of sessions.
i've changed this now to simply request the form value :-)
this value determines which select statement to use

using the code below, i can see the two values i'm comparing.
when i select a radio button and submit the form.
even though i can see which offerid equals the requested form value, the radion button remains unchecked.

thanks
Andy

here is my code:

[FONT='Arial','sans-serif']
Code:
 
[FONT='Arial','sans-serif']<form action="details.asp" method="post" name="form2" id="form2">[/FONT]
[FONT='Arial','sans-serif']<div id="offerwrapper">[/FONT]
[FONT='Arial','sans-serif']<div id="moreoffers">[/FONT]
[FONT='Arial','sans-serif']<div id="copy">Alternative OFFERS for the <%=(RSDetails.Fields.Item("Product").Value)%>  [/FONT]
[FONT='Arial','sans-serif']  <input name="ProductID" type="hidden" id="ProductID" value="<%=(RSDetails.Fields.Item("ProductID").Value)%>" />[/FONT]
[FONT='Arial','sans-serif']</div> [/FONT]
[FONT='Arial','sans-serif']<div id="offerswrap"> [/FONT]
[FONT='Arial','sans-serif']<%Dim offervalue%>[/FONT]
[FONT='Arial','sans-serif']<%[/FONT]
[FONT='Arial','sans-serif']While ((Repeat2__numRows <> 0) AND (NOT RSOffersRest.EOF)) [/FONT]
[FONT='Arial','sans-serif']%> [/FONT]

[FONT='Arial','sans-serif']<div id="offerimage"><a href="details.asp?ProductID=<%=(RSOffersRest.Fields.Item("Offerlink").Value)%>"><img src="products/<%=(RSOffersRest.Fields.Item("Image").Value)%>" width="50" height="50" border="0" /></a></div>     [/FONT]
[FONT='Arial','sans-serif']<div id="offertitle"><%=(RSOffersRest.Fields.Item("Offertext").Value)%><% If(RSOffersRest.Fields.Item("Cost").Value)>0 Then%> [/FONT]
[FONT='Arial','sans-serif']  <span class="style1">Price &pound;<%=(RSOffersRest.Fields.Item("Cost").Value)%></span>[/FONT]
[FONT='Arial','sans-serif']  <% Else%> [/FONT]
[FONT='Arial','sans-serif']  <span class="style1">Free</span> [/FONT]
[FONT='Arial','sans-serif']  <% End If %>[/FONT]
[FONT='Arial','sans-serif']  <input name="productoffer" type="hidden" id="productoffer" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" /> [/FONT]
[FONT='Arial','sans-serif']<% offervalue=(RSOffersRest.Fields.Item("OfferID").Value)%> <%Response.write offervalue %>[/FONT]
[FONT='Arial','sans-serif']</div>[/FONT]
[FONT='Arial','sans-serif']<div id="radios">[/FONT]
[FONT='Arial','sans-serif']<input name="offerselect" type="radio" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" <%If Request("offerselect")=offervalue then%> checked="checked"  <%end if%> />[/FONT]
[FONT='Arial','sans-serif']<%Response.Write Request("offerselect")%>[/FONT]
[FONT='Arial','sans-serif']</div>[/FONT]
[FONT='Arial','sans-serif']<br style="clear:both"/>[/FONT]
[FONT='Arial','sans-serif']  <% [/FONT]
[FONT='Arial','sans-serif']  Repeat2__index=Repeat2__index+1[/FONT]
[FONT='Arial','sans-serif']  Repeat2__numRows=Repeat2__numRows-1[/FONT]
[FONT='Arial','sans-serif']  RSOffersRest.MoveNext()[/FONT]
[FONT='Arial','sans-serif']Wend[/FONT]
[FONT='Arial','sans-serif']%> [/FONT]
[FONT='Arial','sans-serif']<input name="offerchange" type="hidden" id="offerchange" value="yes" />[/FONT]
[FONT='Arial','sans-serif']</div>[/FONT]

[FONT='Arial','sans-serif']</div>[/FONT]
[FONT='Arial','sans-serif']</div>[/FONT]
[FONT='Arial','sans-serif']<div id="submitoffer">[/FONT]
[FONT='Arial','sans-serif']  <div align="center">[/FONT]
[FONT='Arial','sans-serif']    <input name="submit" type="submit" id="submit" value="change offer" />[/FONT]
[FONT='Arial','sans-serif']  </div>[/FONT]
[FONT='Arial','sans-serif']</div>[/FONT]
[FONT='Arial','sans-serif']</form>[/FONT]
[/FONT]
 
Old July 1st, 2012, 06:48 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Three things of note:

> have another look at the code you posted......all those [font] makes it hard to help you
> perhaps I wasn't clear in my question above, is said 'can you post the HTML source of your problematic code? I would liek to see what the value' this is not the HTML source. Run your page, view source in the browser, this is the html source of your code. NOTE - the point of this, as I said in my last post is to, 'see what the value is in: Session("OfferID"), RSOffersRest.Fields.Item("OfferID").Value and you <input name="offerselect"...' SO MAKE SURE YOU PRINT THESE VALUES as you did in the first and second lines of you very first post!!

> after looking through all that annoying [font] garble I have noticed you have done this:

Code:
<input name="offerselect" type="radio" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" <%If Request("offerselect")=offervalue then%> checked="checked"  <%end if%>
You should make extra effort to ensure you are comparing correct data types EG use cint for integers EG

If cint(Request("offerselect"))= cint(offervalue) then

some thing as simple as this will make you page work if you are expecting integers. What values do you think you comparing??? (which is why I asked for the HTML source so I could see these values, please read posts more carefully...)
__________________
Wind is your friend
Matt
 
Old July 2nd, 2012, 05:34 AM
Registered User
 
Join Date: Aug 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your time again mat41

i've added the data type Cint and now i can see that the offervalue is returning all of the offerID's. no wonder i'm not getting any radio button checked.
confused.com!!!
here is my asp code and the output html below:

ASP CODE

Code:
 
<div id="inline1" style="width:560px; display: inherit;">
  <form action="details.asp" method="post" name="form2" id="form2">
<div id="offerwrapper">
<div id="moreoffers">
<div id="copy">Alternative OFFERS for the <%=(RSDetails.Fields.Item("Product").Value)%>  
  <input name="ProductID" type="hidden" id="ProductID" value="<%=(RSDetails.Fields.Item("ProductID").Value)%>" />
</div> 
<div id="offerswrap"> 
<%
While ((Repeat2__numRows <> 0) AND (NOT RSOffersRest.EOF)) 
%> 
<div id="offerimage"><a href="details.asp?ProductID=<%=(RSOffersRest.Fields.Item("Offerlink").Value)%>"><img src="products/<%=(RSOffersRest.Fields.Item("Image").Value)%>" width="50" height="50" border="0" /></a></div>     
<div id="offertitle"><%=(RSOffersRest.Fields.Item("OfferID").Value)%> - <%=(RSOffersRest.Fields.Item("Offertext").Value)%><% If(RSOffersRest.Fields.Item("Cost").Value)>0 Then%> 
  <span class="style1">Price &pound;<%=(RSOffersRest.Fields.Item("Cost").Value)%></span>
  <% Else%> 
  <span class="style1">Free</span> 
  <% End If %>
  <input name="offervalue" type="hidden" id="offervalue" value="<%=(RSOffersRest.Fields.Item("OfferID").Value)%>" />
</div>
<div id="radios">
<%If Cint(Request("offerselect"))=Cint(offervalue) then%>
<input name="offerselect" type="radio" value="<%=Cint(RSOffersRest.Fields.Item("OfferID").Value)%>" checked="checked" />
<% Else%>
<input name="offerselect" type="radio" value="<%=Cint(RSOffersRest.Fields.Item("OfferID").Value)%>"  />
<% End If %>
offerselect=<%Response.Write Request ("offerselect")%>
offervalue=<%Response.Write Request ("offervalue")%>
</div>
<br style="clear:both"/>
  <% 
  Repeat2__index=Repeat2__index+1
  Repeat2__numRows=Repeat2__numRows-1
  RSOffersRest.MoveNext()
Wend
%> 
<input name="offerchange" type="hidden" id="offerchange" value="yes" />
</div>
</div>
</div>
<div id="submitoffer">
  <div align="center">
    <input name="submit" type="submit" id="submit" value="change offer" />
  </div>
</div>
</form>
HTML CODE

Code:
 
<div id="inline1" style="width:560px; display: inherit;">
 
  <form action="details.asp" method="post" name="form2" id="form2">
<div id="offerwrapper">
<div id="moreoffers">
<div id="copy">Alternative OFFERS
  <input name="ProductID" type="hidden" id="ProductID" value="1284" />
</div> 
<div id="offerswrap"> 
 
 
 
 
<div id="offertitle">offer1
<input name="offervalue" type="hidden" id="offervalue" value="693" />
</div>
<div id="radios"> 
<input name="offerselect" type="radio" value="693"  />
 
offerselect=786
offervalue=693, 786, 806, 808
</div>
<br style="clear:both"/>
 
 
 
<div id="offertitle">offer2
<input name="offervalue" type="hidden" id="offervalue" value="786" />
</div>
<div id="radios"> 
<input name="offerselect" type="radio" value="786"  />
 
offerselect=786
offervalue=693, 786, 806, 808
</div>
<br style="clear:both"/>
 
 
 
<div id="offertitle">offer3
<input name="offervalue" type="hidden" id="offervalue" value="806" />
</div>
<div id="radios"> 
<input name="offerselect" type="radio" value="806"  />
 
offerselect=786
offervalue=693, 786, 806, 808
</div>
<br style="clear:both"/>
 
 
 
<div id="offertitle">offer4
<input name="offervalue" type="hidden" id="offervalue" value="808" />
</div>
<div id="radios"> 
<input name="offerselect" type="radio" value="808"  />
 
offerselect=786
offervalue=693, 786, 806, 808
</div>
<br style="clear:both"/>
 
<input name="offerchange" type="hidden" id="offerchange" value="yes" />
</div>
 
</div>
</div>
<div id="submitoffer">
  <div align="center">
    <input name="submit" type="submit" id="submit" value="change offer" />
  </div>
</div>
</form>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Radio button:the challenge is how to validate the selected radio button against the " adamolekunfemi ASP.NET 4 General Discussion 2 December 4th, 2011 09:00 PM
Radio button gaurisharya C# 2005 2 March 16th, 2008 06:43 AM
Radio button Jolley_tolson Javascript 2 July 15th, 2007 05:50 AM
How to restore radio button to unselect status? Edward King Javascript How-To 1 August 17th, 2004 11:31 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.