Onchange session removal

S

sdavids

Hey all, I am wondering if you can remove a session attribute on an
onchange command, this is what I have:

<SELECT name='TestMenu2' onChange='<%session.removeAttribute("test");%>
clearMenu(2);clearMenu(3);this.form.submit();'>

I have 4 menus which are used to run a SQL query, and the test element
is the data in the final drop down box which is selected. Although if
you change the data in any of the previous drop down boxes I want to
remove the session element of the final drop down box since it is no
longer valid. I use the session.getAttribute("test"); in the page
header to display links since it knows that the final element was
selected. But for some reason this isnt working, so I added:

if((request.getParameter("TestMenu4") == null ||
request.getParameter("TestMenu4").equals(""))&&
session.getAttribute("test") != null){
session.removeAttribute("test");
}

to my JSP page which ends up removing the attribute, but doesnt show
the difference in the page header until the page is finally refreshed,
which I dont beleive there is an easy way to do in the if statement. I
tried submitting the form in the if statement after the session
attribute was removed but it lost all of my data from the drop down
box, so I took that out.

Any help would be much appreciated.
 
C

Chris Smith

sdavids said:
Hey all, I am wondering if you can remove a session attribute on an
onchange command, this is what I have:

<SELECT name='TestMenu2' onChange='<%session.removeAttribute("test");%>
clearMenu(2);clearMenu(3);this.form.submit();'>

No, you can't do that. JSP scriptlets are executed on the server when
the page is being created, and can't be attached to JavaScript events in
the manner you're trying to do. The contents of onChange need to be
JavaScript code, which is run on the client. If you want to remove a
session attribute, you'll have to write your JavaScript to generate a
request to the server, and then have a servlet do it on the server.
to my JSP page which ends up removing the attribute, but doesnt show
the difference in the page header until the page is finally refreshed,
which I dont beleive there is an easy way to do in the if statement.

If you want to change the page content, then that's even more involved.
Look into accessing the DOM from JavaScript. None of it is on-topic in
this newsgroup, and I'm sure the people in comp.lang.javascript would be
happy to help.
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top