| Author |
Combo box of a servlet accessing a function in Javascript
|
SJ Rao
Greenhorn
Joined: Mar 05, 2003
Posts: 25
|
|
1) OnChange of combo box, I am trying to call a function which is in "javascript", .js file. 2) I've included the .js file in the script tag in response object of the servlet. 3) But when i click on the combo box, I get an error saying "object expected". Can you please let me know what the error could be. Thanks in advance. I've also included a simple sample here SERVLET FILE public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { sysout.println("<script language=\"javascript \" src=\"fFirstname.js\">"); sysout.println("</script>"); sysout.println("<td> <select id=cmbFirstname name=cmbFirstname onChange=\"fFirstname()\">"); } JavaScript file - fFirstname.js function fFirstname() { alert("hello"); }
|
 |
Kirtikumar Puthran
Ranch Hand
Joined: Mar 04, 2003
Posts: 37
|
|
Hi, "Object expected" is an error which arises bcs of the foll. possible reasons: - The function u are calling is not reachable. - You have mispelled the function name(function name is case-sensitive) - You are trying to call a function which does not exist Try and check the path of the .js file in first case. Rgds, Kirtikumar Puthran
|
Regards,<br />Kirti
|
 |
SJ Rao
Greenhorn
Joined: Mar 05, 2003
Posts: 25
|
|
Hi Kirtikumar, Thanks a lot for your immediate response. I got the solution from one of my friends. 1) There was a error as there was a space after javascript. sysout.println("<script language=\"javascript \" src=\"fFirstname.js\">") 2) And I had to put the javascript file in the defaultwebapp folder or i had to add whatever path i wanted after defaultwebapp like sysout.println("<script language=\"javascript\" src=\"phonebook/javascripts/fFirstname.js\">"); I changed this & its working fine.
|
 |
 |
|
|
subject: Combo box of a servlet accessing a function in Javascript
|
|
|