By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

ASP - Session - checkbox

P: n/a

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

Aug 24 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
<% End If %>
brussels<br>
<input type='checkbox'
name='antwerp'
<% If Request.Form("antwerp")<>"" Then %>
checked
<% End If %>
antwerp<br>
<input type='checkbox'
name='london'
<% If Request.Form("london")<>"" Then %>
checked
<% End If %>
london<br>
<input type='checkbox'
name='newyork'
<% If Request.Form("newyork")<>"" Then %>
checked
<% End If %>
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>
===============================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 24 '07 #2

P: n/a

"Evertjan." <ex**************@interxnl.netschreef in bericht
news:Xn********************@194.109.133.242...
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
<% End If %>
>brussels<br>

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

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

<input type='checkbox'
name='newyork'
<% If Request.Form("newyork")<>"" Then %>
checked
<% End If %>
>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>
===========
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ë

Aug 24 '07 #3

P: n/a
Charlotte wrote on 24 aug 2007 in
microsoft.public.inetserver.asp.general:
>========== 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)

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.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 24 '07 #4

P: n/a

"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
SQL = "... WHERE city = " & cities(0) & " OR city = " & cities(1) &_
" OR city = " & cities(3) & " .... ;"
How about?
....WHERE city IN (cities(0), cities(1), ...etc)
Sep 18 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.