ASP - Session - checkbox

C

Charlotte

Hi,

I have a problem with a ASP-script, can somewone help me ?

here is what I've got:

mypage.asp :

.... code ...
<%
If Request.Form("zzz") = "brussels" Then
Session("city") = "brussels"
End If
If Request.Form("zzz") = "antwerp" Then
Session("city") = "antwerp"
End If
If Request.Form("zzz") = "london" Then
Session("city") = "london"
End If
If Request.Form("zzz") = "newyork" Then
Session("city") = "newyork"
End If
%>
.... code ...
<form action="mypage.asp" method="post" name="xxx">
<table>
<tr><td><input type="checkbox" name="zzz" value="test1" <% If
Session("city") = "brussels" Then %>checked<% End If %>></td></tr>
<tr><td><input type="checkbox" name="zzz" value="test2" <% If
Session("city") = "antwerp" Then %>checked<% End If %>></td></tr>
<tr><td><input type="checkbox" name="zzz" value="test3" <% If
Session("city") = "london" Then %>checked<% End If %>></td></tr>
<tr><td><input type="checkbox" name="zzz" value="test3" <% If
Session("city") = "newyork" Then %>checked<% End If %>></td></tr>
<tr><td><input type="submit" value="submit">
</table>
</form>
.... code ...

So, when the submit-button is clicked and only 1 checkbox is checked, no
problem
the page returns and that checkbox is checked

But when 2 are 3 or ... checkboxes are checked and the page returns
none of the checkboxes are checked
so I want that the checkboxes who were checked
are still be checked after rebuilding the page

I've put a response.write session("city") and the output is (for example)
brussels, antwerp, london

of course it won't work because
If Session("city") = "brussels" Then....
and the session isn't brussels, but
brussels, antwerp, london

so I think that the session must be "split"
so afterwards I can check of the session is that city
and the checkbox of that city must be checked

can somebody give me a script that will do the job
thanks

Charlotte
 
E

Evertjan.

Charlotte wrote on 24 aug 2007 in
microsoft.public.inetserver.asp.general:
Hi,

I have a problem with a ASP-script, can somewone help me ?

here is what I've got:

mypage.asp :

... code ...
<%
If Request.Form("zzz") = "brussels" Then
Session("city") = "brussels"
End If
If Request.Form("zzz") = "antwerp" Then
Session("city") = "antwerp"
End If
If Request.Form("zzz") = "london" Then
Session("city") = "london"
End If
If Request.Form("zzz") = "newyork" Then
Session("city") = "newyork"
End If
%>
... code ...
<form action="mypage.asp" method="post" name="xxx">
<table>
<tr><td><input type="checkbox" name="zzz" value="test1" <% If
Session("city") = "brussels" Then %>checked<% End If %>></td></tr>
<tr><td><input type="checkbox" name="zzz" value="test2" <% If
Session("city") = "antwerp" Then %>checked<% End If %>></td></tr>
<tr><td><input type="checkbox" name="zzz" value="test3" <% If
Session("city") = "london" Then %>checked<% End If %>></td></tr>
<tr><td><input type="checkbox" name="zzz" value="test3" <% If
Session("city") = "newyork" Then %>checked<% End If %>></td></tr>
<tr><td><input type="submit" value="submit">
</table>
</form>
... code ...

So, when the submit-button is clicked and only 1 checkbox is checked,
no problem
the page returns and that checkbox is checked

But when 2 are 3 or ... checkboxes are checked and the page returns
none of the checkboxes are checked
so I want that the checkboxes who were checked
are still be checked after rebuilding the page

I've put a response.write session("city") and the output is (for
example) brussels, antwerp, london

of course it won't work because
If Session("city") = "brussels" Then....
and the session isn't brussels, but
brussels, antwerp, london

so I think that the session must be "split"
so afterwards I can check of the session is that city
and the checkbox of that city must be checked

Try this, there is no need for session variables in the bare case:

========== test1.asp ===========
<form action='' method='post'>

<input type='checkbox'
name='brussels'
<% If Request.Form("brussels")<>"" Then %>
checked
brussels<br>

<input type='checkbox'
name='antwerp'
<% If Request.Form("antwerp")<>"" Then %>
checked
antwerp<br>

<input type='checkbox'
name='london'
<% If Request.Form("london")<>"" Then %>
checked
london<br>

<input type='checkbox'
name='newyork'
<% If Request.Form("newyork")<>"" Then %>
checked
newyork<br>
<input type='submit'>
</form>

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

An even nicer way to do this, I think:

========== test2.asp ===========
<%
function makeCheckbox(nm)
r = "<input type='checkbox' name='"&nm&"' "
If Request.Form(nm)<>"" Then
r = r & "checked "
End If
r = r & "> "&nm&"<br>"
makeCheckbox = r
end function
%>

<form action='' method='post'>
<% = makeCheckbox("brussels") %>
<% = makeCheckbox("antwerp") %>
<% = makeCheckbox("london") %>
<% = makeCheckbox("newyork") %>
<input type='submit'>
</form>
===============================
 
C

Charlotte

Evertjan. said:
Charlotte wrote on 24 aug 2007 in
microsoft.public.inetserver.asp.general:


Try this, there is no need for session variables in the bare case:

========== test1.asp ===========
<form action='' method='post'>

<input type='checkbox'
name='brussels'
<% If Request.Form("brussels")<>"" Then %>
checked


<input type='checkbox'
name='antwerp'
<% If Request.Form("antwerp")<>"" Then %>
checked


<input type='checkbox'
name='london'
<% If Request.Form("london")<>"" Then %>
checked


<input type='checkbox'
name='newyork'
<% If Request.Form("newyork")<>"" Then %>
checked

<input type='submit'>
</form>

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

An even nicer way to do this, I think:

========== test2.asp ===========
<%
function makeCheckbox(nm)
r = "<input type='checkbox' name='"&nm&"' "
If Request.Form(nm)<>"" Then
r = r & "checked "
End If
r = r & "> "&nm&"<br>"
makeCheckbox = r
end function
%>

<form action='' method='post'>
<% = makeCheckbox("brussels") %>
<% = makeCheckbox("antwerp") %>
<% = makeCheckbox("london") %>
<% = makeCheckbox("newyork") %>
<input type='submit'>
</form>
===========
Evertjan.
The Netherlands.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Evertjan,

ik stap dan maar gelijk over naar het Nederlands

bedankt voor uw antwoord, doch één ding heb ik niet vermeld
en dat is dat de content van die sessievariabele ook zou gebruikt worden in
een andere pagina
om daar een select mee te maken (om te filteren)

SQL = "SELECT * FROM xxxxxxxx "
SQL = SQL & "WHERE datum >= #" & start_periode & "# "
SQL = SQL & "AND datum <= #" & einde_periode & "# "
SQL = SQL & "AND ........filtering volgens content van de
variabele..........."

kortom, dat enkel de record van die stad of steden uit de database worden
gehaald

een idee ?

Charlotte
België
 
E

Evertjan.

Charlotte wrote on 24 aug 2007 in
microsoft.public.inetserver.asp.general:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Evertjan,

ik stap dan maar gelijk over naar het Nederlands

bedankt voor uw antwoord, doch ‚‚n ding heb ik niet vermeld
en dat is dat de content van die sessievariabele ook zou gebruikt
worden in een andere pagina
om daar een select mee te maken (om te filteren)


Ja, maar dat maakt toch niet uit, je kan altijd een session variabel
gebruiken om iets op te slaan, maar als je meer mogelijkheden tegelijk
wil opslaan, dan kan je dat niet in één variabele stoppen [of je moet een
grapje uithalen]
SQL = "SELECT * FROM xxxxxxxx "
SQL = SQL & "WHERE datum >= #" & start_periode & "# "
SQL = SQL & "AND datum <= #" & einde_periode & "# "
SQL = SQL & "AND ........filtering volgens content van de
variabele..........."

Sorry, maar daar staat veel meer in, dat hangt helemaal af van de opbouw
van de database. Wil je meer dan 1 record ophalen als je meer dan één
checkbox hebt aanstaan?
kortom, dat enkel de record van die stad of steden uit de database
worden gehaald

een idee ?

Had weinig met die eerste vraag te maken, en een sessie variabel heb je
daar dan toch ook niet strikt voor nodig?

Zet gewoon de gevonden cities in een array en:

SQL = "... WHERE city = " & cities(0) & " OR city = " & cities(1) &_
" OR city = " & cities(3) & " .... ;"

Als het field "city" dan uniek is krijg je voor iedere city maximaal één
record.
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top