aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Date javascript drop downs dynamically filled with jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Date javascript drop downs dynamically filled with jsp" Watch "Date javascript drop downs dynamically filled with jsp" New topic
Author

Date javascript drop downs dynamically filled with jsp

Linda Thomas
Ranch Hand

Joined: Jun 21, 2004
Posts: 36
Our programs use JSP pages with direct access to the database to grab information from tables to fill listboxes. Whenever we have add and update pages for the same object (like add client, update client - though we aren't object based) our supervisor wants us to have add and update pages that call and add_update page.

i.e. addclient.jsp calls add_update.jsp to display the form (passing empty strings and 0 values to add_update.jsp to fill the form)

i.e. updateclient.jsp calls add_update.jsp to display the form (updateclient.jsp grabs values from Object[] passed from class file and sets variables to values grabbed from the database and passes these to add_update.jsp to fill the form)

This is the only project that uses javabeans in our workplace so.

<select name="visitMonth">
<jsp:include page="../listboxes/displayvisitmonth.jsp" flush="true"></jsp:include>
</select>

displayvisitmonth.jsp calls visitbean and if its empty (meaning I'm adding a visit rather than updating one [which would have been uploaded to the visitbean]) then it grabs the current month and puts it in my variable intMonth.

My problems are setting the days range. I have a select statement that tests the values and for Month values 1, 3, 5, 7, 8, 10 and 12 it creates a listbox that displays the range 1-31. If intMonth equals 4, 6, 9 or 11 then the range of the listbox is 1-30. I have a special case to test February to account for leap years.

My problem is when I update. If the user changes the month I need to update the day listbox. I know this is an onChange event; when the user changes the month value then the day should update.

I want to grab the selectedIndex of my month listbox and use it for the day listbox but my attempts have failed. Can I pass it as a <jsp aram> when I call displayvisitday.jsp or can I grab it in displayvisitmonth.jsp. I've tried both but my code is wrong and I get errors. request.getParameter didn't work like it does when I go to a next page. I am having trouble figuring out how to put the selectedIndex in the value of the <jsp aram> tag.

Any ideas? I have a tempvisitbean I use but I've had no luck setting this on the page with a click event.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

If you want to modify the day dropdown as the result of a client-side event (like changing the month dropdown value) then JSP will not help you. Remember that JSP's job is to format the HTML page to send to the client -- once that has been accomplished, its job is done.

Since this is a small and well-known model (which months have how many days and so forth), you can do this completely in Javascript. (If you needed something heavy-weight, like a database lookup then Ajax would be a more approriate choice).

I'm going to move this along to the HTML/Javascript forum for further discussion.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Linda Thomas
Ranch Hand

Joined: Jun 21, 2004
Posts: 36
Yes I can do this in javascript but the way I'm doing it is that inside the select tags I import a jsp page. This is the way our department does it and since we are all students it is imparative that we all follow the same procedures so we can use each other's code to help us with future projects.

Many times when I ask my supervisor how to do something he has requested that I am unfamiliar with he'll just refer me to an older project. In this way we repeat poor, sloppy coding but he just wants it done as fast as we can do it. Basically if it works he is happy. Consistency, effeciency, readability, all these factors are irrelevant to him. But we as students, myself having the most seniority in particular, find it hard to follow old code because each student does things in a different way. So we ourselves, as students, are trying to be consistent with each other so that we and future generations of students will be able to do our job with less aggrivation and less downtime due to trying to figure out how someone did something in old code that is not properly commented.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date javascript drop downs dynamically filled with jsp
 
Similar Threads
doubt in page 494 of HFSJ
Passing values between two JSPs
JSP Forward page param problem with iPlanet
date range in xsl
Newbie help - forms and javabeans