Set qry string value based on radio btn selected

Discussion in 'ASP General' started by mikezx10, Mar 21, 2010.

  1. mikezx10

    mikezx10 Guest

    I have a page that i need to sort if the user selects the sort radio
    btn and then hit the link to reload the page.

    I want to pass a 1 in the querystring for sort if the rb is checked
    and no querystring if the rb isnt checked.

    How can i do this?
    also once the rb is selected when i click it a second time it doesnt
    unselect

    I just inherited a classic asp site and have 1 week experiance so all
    the help u can give apreciated

    Thanks!
    <%@ Language=VBScript %>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    </head>
    <body>
    <%
    dim sort, strSQL
    sort=Request.QueryString("sort")

    if sort=1 then
    strSQL = strSQL & "ORDER BY Date Desc"
    else
    strSQL = strSQL & "ORDER BY fName"
    end if
    %>

    <div id="SelFra" style="POSITION: absolute; WIDTH: 100%;">
    <table width ="100%" border="0" cellspacing="0" align="center" >
    <tr bgcolor="#aeaeae" >
    <td style="width:200px;">&nbsp;&nbsp;
    <input type="radio" name="rbSort" value="0"
    </td>
    <td>
    <a href="Default22.asp?sort=1" >Image</a>
    </td>
    </tr>
    </table>
    </div>
    </body>
    </html>
     
    mikezx10, Mar 21, 2010
    #1
    1. Advertisements

  2. mikezx10

    Bob Barrows Guest

    This is an ASP newsgroup dealing with question about server-side scripting,
    so finding someone to help with a client-side coding question would probably
    be easier if you posted it to a client-side scripting newsgroup like
    m.p.scripting.jscript or comp.lang.javascript

    Incidently, I think the term you were looking for is "submit the form"
    rather than "reload the page".
     
    Bob Barrows, Mar 21, 2010
    #2
    1. Advertisements

  3. mikezx10

    mikezx10 Guest

    This is asp 3.0 code, that is server side is it not?
    what i am doing is changing the sql that will be executed if a radio
    button is select.
     
    mikezx10, Mar 21, 2010
    #3
  4. Gazing into my crystal ball I observed writing in

    Please don't top post. Post corrected, see below:
    Yes, and no. You did not ask the right question, and did not really
    provide any server side code. You also have some markup problems that
    should be dealt with as well.

    <%@ Language=VBScript %> - this is server side, and really not
    necessary, although I do recommend placing most of the server side code
    before anything is output to the client.

    <html xmlns="http://www.w3.org/1999/xhtml">

    Why are you attempting to use XHTML? You would be much better off using
    HTML. Your doctype is incorrect - see an HTML group for the proper way
    to do it.

    <head>
    <title></title>

    No title? How is the user to be able to tell which page he or she is
    on? Especially, if the user needs to change tabs and come back?

    </head>
    <body>
    <%
    dim sort, strSQL
    sort=Request.QueryString("sort")

    This part really should be up at the top, before the HTML declaration.
    Much easier to debug later.

    if sort=1 then
    strSQL = strSQL & "ORDER BY Date Desc"
    else
    strSQL = strSQL & "ORDER BY fName"
    end if

    Understand that 1 is a number, and "1" is a character.
    Request.querystring, and request.form return a character, not a number,
    so this is going to fail.

    Where is your query? How can we possibly help you with your query if
    you don't provide it?

    %>

    I don't see a form element in the markup below. You need that in order
    for the information to go anywhere. I would say that the form should be
    self-submitting. So you need something like:
    <form method="get" action="<%=request.servervariables("script_name")%>">
    You could use the actual page name, but script name is a little more
    portable.

    <div id="SelFra" style="POSITION: absolute; WIDTH: 100%;">
    <table width ="100%" border="0" cellspacing="0" align="center" >
    <tr bgcolor="#aeaeae" >
    <td style="width:200px;">&nbsp;&nbsp;
    <input type="radio" name="rbSort" value="0"
    You are using XHTML, so it would have to be checked="checked", not
    Checked (attributes in XHTML are lower case, and cannot be empty),
    another reason it might fail in modern browsers.

    </td>
    <td>
    <a href="Default22.asp?sort=1" >Image</a>
    </td>

    So the radio button is for presentation only? You would be better off
    doing something with CSS than this.

    </tr>
    </table>
    </div>
    </body>
    </html>

    You would be better off not using tables for presentation. Tables are
    for tabular data, and are a nightmare to maintain, especailly when they
    are nested.

    The most important part here is what the server is receiving from the
    client. In this case you want to test for:

    if request.querystring("sort") = "1" then
    'do something
    else
    'do something else
    end if
     
    Adrienne Boswell, Mar 21, 2010
    #4
  5. mikezx10

    Bob Barrows Guest

    Some of it is. The part that you are asking about (using a radio button to
    set the querystring portion of a querystring) will have to occur entirely on
    the client. You would have the same question if your page's extension was
    ..htm and it did not contain any server-side code, would you not?

    Think of it this way: ASP is server-side technology whose sole purpose is to
    use information contained in the Request to generate html to be sent to the
    client. You can see the generated html by using your browser to view the
    source. Once the html is sent to the client, everything that occurs after
    that point is client-side programming and out of scope of this newsgroup.

    I am not intending this as a rebuke so there is no need for you to get
    defensive. I am simply trying to help you get the answer to your question in
    the most effective way possible.
     
    Bob Barrows, Mar 21, 2010
    #5
  6. mikezx10

    mikezx10 Guest

    Ok I have not read all the msg yet but this is my 1st post ever and
    also i inherited this code. so what is top posting?
     
    mikezx10, Mar 21, 2010
    #6
  7. mikezx10

    mikezx10 Guest

    Ok read the whole thing, 1st thanks so much for the time to give such
    a detailed comment.

    I didnt know xhtml was the case and i cant really change every thing
    being the person that created the page is still with the company and
    it would be bad protocol.

    i think what i really needed to do was check what radio button was
    checked and then set the sql

    I think if i redo the page with a check box not a radio button and
    then at the begining check if the check box was checked that would be
    the answer.

    Sorry for the day 1 questions but how do u check if a check box is
    cheched?
     
    mikezx10, Mar 21, 2010
    #7
  8. Gazing into my crystal ball I observed writing in
    You do it the same way you check for anything coming in from the client.
    It's all about name/value pairs. Name being the name of the form
    control, and value being its value. As I said in my prior post, you
    need to know that a character is going to be returned, not a number.
    So you have to do something like:

    <%
    option explicit

    dim checked

    checked = request.querystring("checkbox")
    if checked = "1" then 'notice the " on either side of the 1
    checked = true
    else
    checked = false
    end if

    %>
    <form method="get" action="<%=request.servervariables("SCRIPT_NAME")%>">
    <p>
    <label for="checkbox">Check me <input name="checkbox" type="checkbox"
    value="1" <% if checked then%>checked="checked"<%end if%> />
    <input type="submit" value="Submit" />
    </p>
    </form>

    This might help you:
    http://www.cavalcade-of-coding.info/requiredform.php
     
    Adrienne Boswell, Mar 22, 2010
    #8
  9. mikezx10

    Evertjan. Guest

    Adrienne Boswell wrote on 22 mrt 2010 in
    microsoft.public.inetserver.asp.general:
    Agreeing with all you wrote, Adrienne, I still think even a beginner
    should know that testing for true/false this way is a bit of code
    overkill, so I would do:

    checked = checked = "1"

    Morover,
    because I'm to lazy to remember what the browser will return,
    [my Chrome returns "on", I just found], I check for the absence of this
    supposed trueness:

    checked = checked <> ""

    ========= test.asp ==========
    Returned text: <% = request.querystring("myCheckbox") %>
    <hr>
    Testing for "1": <% = request.querystring("myCheckbox")="1" %>
    <hr>
    Testing for "on": <% = request.querystring("myCheckbox")="on" %>
    <hr>
    Testing for not "": <% = request.querystring("myCheckbox")<>"" %>
    <hr>
    <form>
    <input type='checkbox' name='myCheckbox' checked>
    <input type='submit'>
    </form>
    =============================

    This returns if checked and submitted:

    Returned text: on
    Testing for "1": False
    Testing for "on": True
    Testing for not "": True
     
    Evertjan., Mar 22, 2010
    #9
  10. mikezx10

    MikeR Guest

    Top posting is putting your replies on top of the stuff you're replying to, instead
    of after it.

    Mike
     
    MikeR, Mar 22, 2010
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.