• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting this Ajax code to work with jsp

 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I need some help to implement a filter on a dropdown list in a jsp page using Javascript. I have got the filtering working in Java code and jsp, but do not know how to use javascript to run the jsp on changes made to the dropdown.

Basically, I have three dropdown list, the first of displays the list of student names, second one displays list of exams taken and the last one displays exams passed. What I am trying to do is, when the user selects a student name from the first dropdown, it filters the second dropdown list and only displays the exams taken by the student name selected in the first dropdown. And similarly when the user selects exams taken from the second dropdown, it filters the third dropdown and only displays the list of exams passed by student name and exam name selected in the above two dropdowns.

I have got the filtering working in the java code and the filter works fine in jsp, providing I keep presses the refresh button. I need help with the Javascript event.

Below is my code in jsp:

Here is my explanation of the above:

1. The first dropdown simply creates a list of student name by using method <%=student.getList(stuForm.getStudentID())%>

2. The second dropdown creates a list of exams details by taking in a value returned by stuForm.getStudentID(), and if the dropdown was already selected then it would display the current value returned by stuForm.getExamID()
<%=exam.createList(stuForm.getStudentID(), stuForm.getExamID())%>

3. The third dropdown creates a list of exam passed by taking in values returned by stuForm.getStudentID() and stuForm.getExamID() and if the dropdown was already slected then it would display the current value returned by stuForm.getPassID()

I hope I am making sense. Again I need help with javascript that could pass the right IDs and run the method on clientside based on changes in the dropdown. I am a newbie in javascript and would really appreciate any help and guidance.

Thanks
Zub

[ March 23, 2008: Message edited by: Bear Bibeault ]

[ March 23, 2008: Message edited by: Bear Bibeault ]

[ March 25, 2008: Message edited by: Zubi Pen ]
[ March 25, 2008: Message edited by: Bear Bibeault ]
 
pravin kantipudi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey do this , I am not sure what you want to do with thta value. just to give you a start

<script type="text/javascript">
function eun(var id) {
//retrieve the value using this statement
document.getElementById(id).value
}
</script>

<select name="studentID" id="studentID" onchange="javascript:run(studentID);return false;">

<select name="examID" id="examID" onchange="javascript:run(examID);return false;">

<select name="passID" id="passID" onchange="javascript:run(passID);return false;">
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65125
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
onchange="javascript:


This is not correct. You do not specify any pseudo-protocol on event handler attributes.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65125
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zubi Pen, you have a misunderstanding regarding how JSP's work. The JSP runs on the server in order to format the page and send it to the browser. Once sent, it is no longer possible to use JSP mechanisms.

Please read this article for an explanation.
 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the replies and advise.

Once sent, it is no longer possible to use JSP mechanisms.


In this case, how can I run a Filter on the dropdown on the client side then? I simply want to filter the dropdowns based on user selections. A simple example will be if user selects United Kingdom in the country dropdown and then in the city Dropdown it returns all the cities located in UK. The only thing is my case is the DropDown List is created using a method called createList() passing the appropriate parameter.
[ March 24, 2008: Message edited by: Zubi Pen ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65125
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zubi Pen:
In this case, how can I run a Filter on the dropdown on the client side then?
If the operation must contact the server, to grab the info from a DB for example, you must make a new request to the server. Nowadays, Ajax is the most common means to perform such ancillary contacts (rather than submitting and refreshing the whole page).
[ March 24, 2008: Message edited by: Bear Bibeault ]
 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you guys advised me to use Ajax to filter the dynamic dropdown, I used the code from this Ajax site, heres the link:

Ajax

But it doesnt seem to work. Below is my full jsp code. Could anymore advise me how to get the ajax code to work with my jsp page.

 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot seem to figure out the Ajax code here, is there any Javascript code that simply reloads the page each time I have a selection in the dropdown
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zubi Pen:
Since you guys advised me to use Ajax to filter the dynamic dropdown, I used the code from this Ajax site, heres the link:
[/CODE]


Dear Zubi,
AJAX can help you in your problem. Tell me how did you implement AJAX in your code. Are you able to make a hit on server whenever you click on a dropdown.

Best Regards
 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pat,

Thanks for your reply. I have got it to work in Ajax, I was passing the wrong student ID which was causing the problem all along...

Thanks,
Zub
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic