Is there a better way to do this?

Discussion in 'ASP General' started by Jerry, Mar 15, 2005.

  1. Jerry

    Jerry Guest

    I'm creating a survey for our organization that consists of about 38
    statements that need to be rated on a scale of 1 to 5. The survey is for
    a very specific audience and all of the questions are required. I'm
    using radio buttons for the ratings and am wondering if I'm handeling
    this the best way to preserve the user's answers if they missed a
    question and have to go back to answer.

    Here is what I have (this would be for each question):
    <%
    dim arr1(4)

    select case session("1")
    case "5" arr(4) = "SELECTED"
    case "4" arr(3) = "SELECTED"
    case "3" arr(2) = "SELECTED"
    case "2" arr(1) = "SELECTED"
    case "1" arr(0) = "SELECTED"
    end select
    %>

    5<input type="radio" name="1" value="5"<%=arr(4)%>>
    4<input type="radio" name="1" value="4"<%=arr(3)%>>
    3<input type="radio" name="1" value="3"<%=arr(2)%>>
    2<input type="radio" name="1" value="2"<%=arr(1)%>>
    1<input type="radio" name="1" value="1"<%=arr(0)%>>

    Is there a better, more efficient way to do this?

    Thanks,

    --
    Jerry
     
    Jerry, Mar 15, 2005
    #1
    1. Advertising

  2. Jerry

    Evertjan. Guest

    Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:

    > Here is what I have (this would be for each question):
    > <%
    > dim arr1(4)
    >
    > select case session("1")
    > case "5" arr(4) = "SELECTED"
    > case "4" arr(3) = "SELECTED"
    > case "3" arr(2) = "SELECTED"
    > case "2" arr(1) = "SELECTED"
    > case "1" arr(0) = "SELECTED"
    > end select
    > %>


    "selected" should be "checked"

    > 5<input type="radio" name="1" value="5"<%=arr(4)%>>
    > 4<input type="radio" name="1" value="4"<%=arr(3)%>>
    > 3<input type="radio" name="1" value="3"<%=arr(2)%>>
    > 2<input type="radio" name="1" value="2"<%=arr(1)%>>
    > 1<input type="radio" name="1" value="1"<%=arr(0)%>>
    >
    > Is there a better, more efficient way to do this?
    >




    <%
    function sel(x)
    sel = ""
    if x = session("1") then sel = "checked"
    end functon
    %>

    5 <input type="radio" name="1" value="5" <%=sel(5)%>>
    4 <input type="radio" name="1" value="4" <%=sel(4)%>>
    3 <input type="radio" name="1" value="3" <%=sel(3)%>>
    2 <input type="radio" name="1" value="2" <%=sel(2)%>>
    1 <input type="radio" name="1" value="1" <%=sel(1)%>>



    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Mar 15, 2005
    #2
    1. Advertising

  3. Jerry

    Jerry Guest

    Evertjan. wrote:
    > <%
    > function sel(x)
    > sel = ""
    > if x = session("1") then sel = "checked"
    > end functon
    > %>
    >
    > 5 <input type="radio" name="1" value="5" <%=sel(5)%>>
    > 4 <input type="radio" name="1" value="4" <%=sel(4)%>>
    > 3 <input type="radio" name="1" value="3" <%=sel(3)%>>
    > 2 <input type="radio" name="1" value="2" <%=sel(2)%>>
    > 1 <input type="radio" name="1" value="1" <%=sel(1)%>>
    >


    I tried to call the function like this:
    <%
    function sel(x)
    sel = ""
    if x = session("1") then sel = " checked"
    end function

    call sel(session("1"))
    %>
    5<input type="radio" name="1" value="5"<%=sel(5)%>>
    4<input type="radio" name="1" value="4"<%=sel(4)%>>
    3<input type="radio" name="1" value="3"<%=sel(3)%>>
    2<input type="radio" name="1" value="2"<%=sel(2)%>>
    1<input type="radio" name="1" value="1"<%=sel(1)%>>

    I could not get it to work. I'm sorry, I'm not very familiar with ASP
    functions. Could you point out what I'm doing wrong here?


    --
    Jerry
     
    Jerry, Mar 15, 2005
    #3
  4. Jerry

    Evertjan. Guest

    Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >> <%
    >> function sel(x)
    >> sel = ""
    >> if x = session("1") then sel = "checked"
    >> end functon
    >> %>
    >>
    >> 5 <input type="radio" name="1" value="5" <%=sel(5)%>>
    >> 4 <input type="radio" name="1" value="4" <%=sel(4)%>>
    >> 3 <input type="radio" name="1" value="3" <%=sel(3)%>>
    >> 2 <input type="radio" name="1" value="2" <%=sel(2)%>>
    >> 1 <input type="radio" name="1" value="1" <%=sel(1)%>>
    >>

    >
    > I tried to call the function like this:
    > <%
    > function sel(x)
    > sel = ""
    > if x = session("1") then sel = " checked"
    > end function
    >


    > call sel(session("1"))


    No that call does not work. the <%=sel(5)%> is the call


    > %>
    > 5<input type="radio" name="1" value="5"<%=sel(5)%>>


    Why do you change my code? do not delete neccessary spaces!

    <input type="radio" name="1" value="5" <%=sel(5)%>>


    > 4<input type="radio" name="1" value="4"<%=sel(4)%>>
    > 3<input type="radio" name="1" value="3"<%=sel(3)%>>
    > 2<input type="radio" name="1" value="2"<%=sel(2)%>>
    > 1<input type="radio" name="1" value="1"<%=sel(1)%>>
    >
    > I could not get it to work. I'm sorry, I'm not very familiar with ASP
    > functions. Could you point out what I'm doing wrong here?


    This NG usually and I certainly expect some familiarity or self
    experiment with ASP.

    Does a test.asp page with only:

    <%="Hello World"%>

    produce

    Hello World

    ?


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Mar 15, 2005
    #4
  5. Jerry

    Jerry Guest

    Evertjan. wrote:
    > Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >
    >
    >>Evertjan. wrote:
    >>
    >>><%
    >>>function sel(x)
    >>> sel = ""
    >>> if x = session("1") then sel = "checked"
    >>>end functon
    >>>%>
    >>>
    >>>5 <input type="radio" name="1" value="5" <%=sel(5)%>>
    >>>4 <input type="radio" name="1" value="4" <%=sel(4)%>>
    >>>3 <input type="radio" name="1" value="3" <%=sel(3)%>>
    >>>2 <input type="radio" name="1" value="2" <%=sel(2)%>>
    >>>1 <input type="radio" name="1" value="1" <%=sel(1)%>>
    >>>

    >>I tried to call the function like this:
    >><%
    >>function sel(x)
    >> sel = ""
    >> if x = session("1") then sel = " checked"
    >>end function
    >>

    >
    >
    >>call sel(session("1"))

    >
    >
    > No that call does not work. the <%=sel(5)%> is the call
    >
    >
    >
    >>%>
    >>5<input type="radio" name="1" value="5"<%=sel(5)%>>

    >
    >
    > Why do you change my code? do not delete neccessary spaces!


    It didn't work so I experimented a little.

    > <input type="radio" name="1" value="5" <%=sel(5)%>>
    >
    >
    >>4<input type="radio" name="1" value="4"<%=sel(4)%>>
    >>3<input type="radio" name="1" value="3"<%=sel(3)%>>
    >>2<input type="radio" name="1" value="2"<%=sel(2)%>>
    >>1<input type="radio" name="1" value="1"<%=sel(1)%>>
    >>
    >>I could not get it to work. I'm sorry, I'm not very familiar with ASP
    >>functions. Could you point out what I'm doing wrong here?

    >
    >
    > This NG usually and I certainly expect some familiarity or self
    > experiment with ASP.


    I'm familiar with ASP. I've just never used functions that much. My job
    requires a little ASP coding but not much. The code example didn't work
    so I experimented a little. Obviously I was going the wrong direction.

    > Does a test.asp page with only:
    >
    > <%="Hello World"%>
    >
    > produce
    >
    > Hello World
    >
    > ?


    <sigh>


    --
    Jerry
     
    Jerry, Mar 15, 2005
    #5
  6. Jerry

    Evertjan. Guest

    Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:

    >> Does a test.asp page with only:
    >>
    >> <%="Hello World"%>
    >>
    >> produce
    >>
    >> Hello World
    >>
    >> ?

    >
    > <sigh>
    >


    This is not a joke.
    It is a serious attemt to help you.


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Mar 15, 2005
    #6
  7. Jerry

    Jerry Guest

    Evertjan. wrote:
    > Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >
    >
    >>>Does a test.asp page with only:
    >>>
    >>><%="Hello World"%>
    >>>
    >>>produce
    >>>
    >>>Hello World
    >>>
    >>>?

    >>
    >><sigh>
    >>

    >
    > This is not a joke.
    > It is a serious attemt to help you.
    >


    The example above would produce "Hello World".


    --
    Jerry
     
    Jerry, Mar 15, 2005
    #7
  8. Jerry

    Evertjan. Guest

    Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >> Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >>
    >>
    >>>>Does a test.asp page with only:
    >>>>
    >>>><%="Hello World"%>
    >>>>
    >>>>produce
    >>>>
    >>>>Hello World
    >>>>
    >>>>?
    >>>
    >>><sigh>
    >>>

    >>
    >> This is not a joke.
    >> It is a serious attemt to help you.
    >>

    >
    > The example above would produce "Hello World".


    Jerry, the question is not what is WOULD produce,
    but it is the first debugging test
    if your asp enging is working.

    It seems, since as you profes,
    your knowledge of asp functions is limited,
    that serious debugging is necessary.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Mar 15, 2005
    #8
  9. Jerry

    Jerry Guest

    Evertjan. wrote:
    > Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >
    >
    >>Evertjan. wrote:
    >>
    >>>Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >>>
    >>>
    >>>
    >>>>>Does a test.asp page with only:
    >>>>>
    >>>>><%="Hello World"%>
    >>>>>
    >>>>>produce
    >>>>>
    >>>>>Hello World
    >>>>>
    >>>>>?
    >>>>
    >>>><sigh>
    >>>>
    >>>This is not a joke.
    >>>It is a serious attemt to help you.
    >>>

    >>
    >>The example above would produce "Hello World".

    >
    >
    > Jerry, the question is not what is WOULD produce,
    > but it is the first debugging test
    > if your asp enging is working.
    >
    > It seems, since as you profes,
    > your knowledge of asp functions is limited,
    > that serious debugging is necessary.
    >


    Ah, I didn't quite understand you earlier. The answer to your question
    is yes, that does work. I have various other ASP pages on my website
    that are also currently working (I just checked after reading your reply).


    --
    Jerry
     
    Jerry, Mar 15, 2005
    #9
  10. Jerry

    Jerry Guest

    Jerry wrote:
    > Evertjan. wrote:
    >
    >> Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >>
    >>
    >>> Evertjan. wrote:
    >>>
    >>>> Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >>>>
    >>>>
    >>>>
    >>>>>> Does a test.asp page with only:
    >>>>>>
    >>>>>> <%="Hello World"%>
    >>>>>>
    >>>>>> produce
    >>>>>> Hello World
    >>>>>>
    >>>>>> ?
    >>>>>
    >>>>>
    >>>>> <sigh>
    >>>>>
    >>>> This is not a joke. It is a serious attemt to help you.
    >>>>
    >>>
    >>> The example above would produce "Hello World".

    >>
    >>
    >>
    >> Jerry, the question is not what is WOULD produce, but it is the first
    >> debugging test if your asp enging is working.
    >>
    >> It seems, since as you profes, your knowledge of asp functions is
    >> limited, that serious debugging is necessary.
    >>

    >
    > Ah, I didn't quite understand you earlier. The answer to your question
    > is yes, that does work. I have various other ASP pages on my website
    > that are also currently working (I just checked after reading your reply).
    >
    >


    This worked:

    <%
    function sel(x)
    sel = ""
    if (x*1) = (session("1")*1) then sel = "checked"
    end function
    %>
    5<input type="radio" name="1" value="5" <%=sel(5)%>>
    4<input type="radio" name="1" value="4" <%=sel(4)%>>
    3<input type="radio" name="1" value="3" <%=sel(3)%>>
    2<input type="radio" name="1" value="2" <%=sel(2)%>>
    1<input type="radio" name="1" value="1" <%=sel(1)%>>

    I think the problem was that session("1") was not numeric so it didn't
    equal the numeric value of x.


    --
    Jerry
     
    Jerry, Mar 15, 2005
    #10
  11. Jerry

    Evertjan. Guest

    Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:

    > Ah, I didn't quite understand you earlier. The answer to your question
    > is yes, that does work. I have various other ASP pages on my website
    > that are also currently working (I just checked after reading your
    > reply).
    >
    >


    Than the next question is, does this work:

    =========== test.asp =============

    <%
    function sel(x)
    sel = ""
    if x = session("1") then sel = "checked"
    end function

    session("1") = "myTest"
    %>

    myTest: <%=sel("myTest")%>
    <br>
    yourTest: <%=sel("yourTest")%>

    ============================

    on my system it shows:

    myTest: checked
    yourTest:

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Mar 15, 2005
    #11
  12. Jerry

    Jerry Guest

    Evertjan. wrote:
    > Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
    >
    >
    >>Ah, I didn't quite understand you earlier. The answer to your question
    >>is yes, that does work. I have various other ASP pages on my website
    >>that are also currently working (I just checked after reading your
    >>reply).
    >>
    >>

    >
    >
    > Than the next question is, does this work:
    >
    > =========== test.asp =============
    >
    > <%
    > function sel(x)
    > sel = ""
    > if x = session("1") then sel = "checked"
    > end function
    >
    > session("1") = "myTest"
    > %>
    >
    > myTest: <%=sel("myTest")%>
    > <br>
    > yourTest: <%=sel("yourTest")%>
    >
    > ============================
    >
    > on my system it shows:
    >
    > myTest: checked
    > yourTest:
    >


    I get the same results.


    --
    Jerry
     
    Jerry, Mar 15, 2005
    #12
    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. dwa

    There MUST be a better way!

    dwa, Jan 28, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    439
    Marauderz
    Jan 29, 2004
  2. Guadala Harry

    Nested DIVs - is there a better way?

    Guadala Harry, Oct 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    496
    Guadala Harry
    Oct 26, 2004
  3. Peter Bencsik
    Replies:
    2
    Views:
    857
  4. Paul Rubin
    Replies:
    5
    Views:
    428
    Hendrik van Rooyen
    Aug 6, 2009
  5. Replies:
    2
    Views:
    61
    Mark H Harris
    May 13, 2014
Loading...

Share This Page