Is there a better way to do this?

J

Jerry

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,
 
E

Evertjan.

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)%>>
 
J

Jerry

Evertjan. said:
<%
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?
 
E

Evertjan.

Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
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)%>>

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

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

?
 
J

Jerry

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




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





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

It didn't work so I experimented a little.
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>
 
J

Jerry

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



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

The example above would produce "Hello World".
 
E

Evertjan.

Jerry wrote on 15 mrt 2005 in microsoft.public.inetserver.asp.general:
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.
 
J

Jerry

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




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).
 
J

Jerry

Jerry said:
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.
 
E

Evertjan.

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:
 
J

Jerry

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




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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top