wood burning stoves 2.0*
The moose likes Servlets and the fly likes Combo box of a servlet accessing a function in Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Combo box of a servlet accessing a function in Javascript" Watch "Combo box of a servlet accessing a function in Javascript" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Combo box of a servlet accessing a function in Javascript
 
Similar Threads
Calling javascript function in js file from JSP
call javascript function from external JS file
Can't include .js file on jsp page controlled by front controller servlet
Why always show the javascript class AutoSuggestControl is not defined?
Script using array