how to reselect radio button in asp

Discussion in 'ASP General' started by weiwei, Jan 7, 2010.

  1. weiwei

    weiwei Guest

    Hi
    I have a record input in radio button style and store in the database,
    then user query it out and display in radio button style in the form.
    Then if that user changes his mind and want to reselect other choice,

    So far, I am reaching the last part, every time user selected another
    radio button and click submit, I still see the old radio button result
    instead of new one.

    Any idea??? (below is my example code)
    thanks in advance

    First page to select radio button and hit submit

    <td class="cat">Quickly builds rapport and identifies customer’s
    needs in order to book rental.</td>

    <td class="catc"><input type="radio" name="num1" value="1" /></td>

    <td class="catc"><input type="radio" name="num1" value="2" /></td>

    <td class="catc"><input type="radio" name="num1" value="3" /></td>

    <td class="catc"><input type="radio" name="num1" value="4" /></td>

    <td class="catc"><input type="radio" name="num1" value="5" /></td>

    </tr>



    Second page I pick it up the variable and do a select case statement,
    if user chose choice 1 and it will show up as choice 1. now if user
    change mind and want to change to choice 2, I can do it from it
    screen, and click submit, I will getting choice 1 instead of new
    choice 2



    <% strnum1 = request.form(“num1”) %>

    <% Select Case strnum1 %>

    <% Case 1 %>

    <td class="catc"><input type="radio" name="num1" value="1" Checked /></
    td>

    <td class="catc"><input type="radio" name="num1" value="1" /></td>

    <td class="catc"><input type="radio" name="num1" value="1" /></td>

    <td class="catc"><input type="radio" name="num1" value="1" /></td>

    <td class="catc"><input type="radio" name="num1" value="1" /></td>

    <% case 2 %>

    <td class="catc"><input type="radio" name="num1" value="2" /></td>

    <td class="catc"><input type="radio" name="num1" value="2" Checked /></
    td>

    <td class="catc"><input type="radio" name="num1" value="2" /></td>

    <td class="catc"><input type="radio" name="num1" value="2" /></td>

    <td class="catc"><input type="radio" name="num1" value="2" /></td>

    </ End Select %>
    weiwei, Jan 7, 2010
    #1
    1. Advertising

  2. weiwei <> wrote in news:f6feaa4b-c19c-409e-ac26-
    :

    > Hi
    > I have a record input in radio button style and store in the database,
    > then user query it out and display in radio button style in the form.
    > Then if that user changes his mind and want to reselect other choice,
    >
    > So far, I am reaching the last part, every time user selected another
    > radio button and click submit, I still see the old radio button result
    > instead of new one.
    >
    > Any idea??? (below is my example code)
    > thanks in advance
    >
    > First page to select radio button and hit submit
    >
    > <td class="cat">Quickly builds rapport and identifies customer’s
    > needs in order to book rental.</td>
    >
    > <td class="catc"><input type="radio" name="num1" value="1" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="2" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="3" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="4" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="5" /></td>
    >
    > </tr>
    >
    >
    >
    > Second page I pick it up the variable and do a select case statement,
    > if user chose choice 1 and it will show up as choice 1. now if user
    > change mind and want to change to choice 2, I can do it from it
    > screen, and click submit, I will getting choice 1 instead of new
    > choice 2
    >
    >
    >
    > <% strnum1 = request.form(“num1”) %>
    >
    > <% Select Case strnum1 %>
    >
    > <% Case 1 %>
    >
    > <td class="catc"><input type="radio" name="num1" value="1" Checked />

    </
    > td>
    >
    > <td class="catc"><input type="radio" name="num1" value="1" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="1" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="1" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="1" /></td>
    >
    > <% case 2 %>
    >
    > <td class="catc"><input type="radio" name="num1" value="2" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="2" Checked />

    </
    > td>
    >
    > <td class="catc"><input type="radio" name="num1" value="2" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="2" /></td>
    >
    > <td class="catc"><input type="radio" name="num1" value="2" /></td>
    >
    > </ End Select %>



    This is how I do things like this. First of all, almost all forms I do
    post to themselves, and avoid these kind of issues. You are also using
    XHTML syntax which required that all attributes have values, eg:
    checked="checked" is valid, while just checked is not. That might also
    have something to do with it.

    <% num1 = request.form("num1") %>

    <input type="radio" name="num1" value="1" <% if num1="1" then%>
    checked="checked"<%end if%> />


    or you can use a function:

    <input type="radio" name="num1" value="1" <%=chkchkd(1,num1)%> />

    <%
    function chkchkd(value,selected)
    if value = selected then
    chk = "checked=" & chr(34) & "checked" & chr(34)
    else
    chk = ""
    end if

    chkchkd = chk
    end function
    %>

    heck, you can even put it through a loop:

    <% for i = 1 to 5 %>
    <input type="radio" name="num1" value="<%=i%>" <%=chkchkd(i,num1)%> />
    <% next%>

    --
    Adrienne Boswell at work
    Please respond to the group so others can share
    nextBlock.com
    http://nextblock.com/
    Adrienne Boswell, Jan 7, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott D Johnson
    Replies:
    1
    Views:
    1,062
    Scott D Johnson
    Sep 27, 2006
  2. tshad
    Replies:
    6
    Views:
    6,960
    Alexey Smirnov
    Nov 26, 2009
  3. Martin
    Replies:
    8
    Views:
    3,337
    Jan C. Faerber
    Nov 24, 2009
  4. Hiten
    Replies:
    1
    Views:
    617
    Vidar Petursson
    May 26, 2004
  5. Jedi Knight
    Replies:
    0
    Views:
    110
    Jedi Knight
    Jul 19, 2005
Loading...

Share This Page