473,795 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP - Session - checkbox


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("z zz") = "brussels" Then
Session("city") = "brussels"
End If
If Request.Form("z zz") = "antwerp" Then
Session("city") = "antwerp"
End If
If Request.Form("z zz") = "london" Then
Session("city") = "london"
End If
If Request.Form("z zz") = "newyork" Then
Session("city") = "newyork"
End If
%>
.... code ...
<form action="mypage. asp" method="post" name="xxx">
<table>
<tr><td><inpu t type="checkbox" name="zzz" value="test1" <% If
Session("city") = "brussels" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t type="checkbox" name="zzz" value="test2" <% If
Session("city") = "antwerp" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t type="checkbox" name="zzz" value="test3" <% If
Session("city") = "london" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t type="checkbox" name="zzz" value="test3" <% If
Session("city") = "newyork" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t 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
4 4439
Charlotte wrote on 24 aug 2007 in
microsoft.publi c.inetserver.as p.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("z zz") = "brussels" Then
Session("city") = "brussels"
End If
If Request.Form("z zz") = "antwerp" Then
Session("city") = "antwerp"
End If
If Request.Form("z zz") = "london" Then
Session("city") = "london"
End If
If Request.Form("z zz") = "newyork" Then
Session("city") = "newyork"
End If
%>
... code ...
<form action="mypage. asp" method="post" name="xxx">
<table>
<tr><td><inpu t type="checkbox" name="zzz" value="test1" <% If
Session("city") = "brussels" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t type="checkbox" name="zzz" value="test2" <% If
Session("city") = "antwerp" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t type="checkbox" name="zzz" value="test3" <% If
Session("city") = "london" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t type="checkbox" name="zzz" value="test3" <% If
Session("city") = "newyork" Then %>checked<% End If %>></td></tr>
<tr><td><inpu t 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("b russels")<>"" Then %>
checked
<% End If %>
brussels<br>
<input type='checkbox'
name='antwerp'
<% If Request.Form("a ntwerp")<>"" Then %>
checked
<% End If %>
antwerp<br>
<input type='checkbox'
name='london'
<% If Request.Form("l ondon")<>"" Then %>
checked
<% End If %>
london<br>
<input type='checkbox'
name='newyork'
<% If Request.Form("n ewyork")<>"" 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("b russels") %>
<% = makeCheckbox("a ntwerp") %>
<% = makeCheckbox("l ondon") %>
<% = makeCheckbox("n ewyork") %>
<input type='submit'>
</form>
=============== =============== =

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

"Evertjan." <ex************ **@interxnl.net schreef in bericht
news:Xn******** ************@19 4.109.133.242.. .
Charlotte wrote on 24 aug 2007 in
microsoft.publi c.inetserver.as p.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("z zz") = "brussels" Then
Session("city") = "brussels"
End If
If Request.Form("z zz") = "antwerp" Then
Session("city") = "antwerp"
End If
If Request.Form("z zz") = "london" Then
Session("city") = "london"
End If
If Request.Form("z zz") = "newyork" Then
Session("city") = "newyork"
End If
%>
... code ...
<form action="mypage. asp" method="post" name="xxx">
<table>
<tr><td><inp ut type="checkbox" name="zzz" value="test1" <% If
Session("city" ) = "brussels" Then %>checked<% End If %>></td></tr>
<tr><td><inp ut type="checkbox" name="zzz" value="test2" <% If
Session("city" ) = "antwerp" Then %>checked<% End If %>></td></tr>
<tr><td><inp ut type="checkbox" name="zzz" value="test3" <% If
Session("city" ) = "london" Then %>checked<% End If %>></td></tr>
<tr><td><inp ut type="checkbox" name="zzz" value="test3" <% If
Session("city" ) = "newyork" Then %>checked<% End If %>></td></tr>
<tr><td><inp ut 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("b russels")<>"" Then %>
checked
<% End If %>
>brussels<br>

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

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

<input type='checkbox'
name='newyork'
<% If Request.Form("n ewyork")<>"" 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("b russels") %>
<% = makeCheckbox("a ntwerp") %>
<% = makeCheckbox("l ondon") %>
<% = makeCheckbox("n ewyork") %>
<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 ........filteri ng 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
Charlotte wrote on 24 aug 2007 in
microsoft.publi c.inetserver.as p.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("b russels") %>
<% = makeCheckbox("a ntwerp") %>
<% = makeCheckbox("l ondon") %>
<% = makeCheckbox("n ewyork") %>
<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 ........filteri ng 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

"Evertjan." <ex************ **@interxnl.net wrote in message
news:Xn******** ************@19 4.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1683
by: Josh Santangelo | last post by:
I'm building a simple login form with a "remember me" checkbox. I've done this before, just keeping the username and a hash of the password in a cookie, and changing the expiration of the cookie based on the checkbox, but this time I want to use sessions instead. There's another site I was looking at which gives you a session cookie immediately. When you log in, log out, quit the browser, or anything, the cookie still contains the same...
1
5485
by: Pete | last post by:
I have some session variables which get set on page one of my site. I can set an unset these by passing through a parameter in some URL's. When the user goes to the second page some checkboxes are checked if their corresponding session variable is set and has a value of "true". The problem I have is that if the user unchecks a checkbox before finally moving to page three (which is perfectly okay for them to do if they wish) then I need...
6
2393
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an email from (possibly) three seperate forms. the following code is the end of a routine which stashes data from the first form off to session variables and then redirects itself to the proper form / procedure depending upon the state of two...
6
1527
by: Mike | last post by:
I have a function that is called when the user clicks the submit button, during this function i also set a varaible to "Y" due to that this function does a post back to the page then redirects. When I look for the session variable in the page.isPostBack section it equals nothing, it appears that the variable is not being passed to the post back section correctly. I have this due to I only want this function to run if the user has something...
2
1774
by: gce | last post by:
What happens : When I first press the button, I get an listbox1 with a,b,c (correct: because of the addtoa(1, "a") addtoa(2, "b") addtoa(3, "c") When I check the checkbox, the eventhandler triggers and when I press the button, the addtoa(4,"d") works fine, because I have a listbox with a,b,c,d
14
2382
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and User B has access to 5, now when both of us hits to the server at the same time then their session variables gets mixedup means either User A and USer B will have now 5 companies or both have 10 companies. Now again when User A hits to the server...
7
3968
by: aroraamit81 | last post by:
Well Guys, Here is a very strange trouble. When more than one users request tto same page at the same time then our session gets conflicted. Moreover I printed my SessionID, strangely but true I got the exact same SessionID as of other users's. Well I guess nothing wrong with my code, do I need to set any property in Web.Config file??
1
2416
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books to buy from the datagrid. User can select books using checkboxes in the datagrid. The selected books are stored in a session variable name session("temp") which is a dataset type.After storing dataset in session (in bold letters),user will...
0
1995
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books to buy from the datagrid. User can select books using checkboxes in the datagrid. The selected books are stored in a session variable name session("temp") which is a dataset type.After storing dataset in session (in bold letters),user will...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.