This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes parameter passing to Java Script function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "parameter passing to Java Script function" Watch "parameter passing to Java Script function" New topic
Author

parameter passing to Java Script function

sanjivani g
Greenhorn

Joined: Sep 18, 2000
Posts: 2
Hi!
I'm trying to pass a parameter to the Java Script function in a servlet, but the parameter is being undefined in the function. Please let me know where I'm doing the mistake.
Here's my code :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ChPswdPJavaRanch extends HttpServlet {
String someVar="Some String";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session = request.getSession(true);
response.setContentType("text/html");
PrintWriter out = response.getWriter();;
out.println("<html>");
out.println("<head>");
out.println("<SCRIPT LANGUAGE=\"JavaScript\">");
out.println("<!-- Begin");
out.println("function check(param) { ");
out.println("document.write(\"function parameter :\"+param)");
out.println("}");
out.println("// End -->");
out.println("</SCRIPT>");
out.println("</head>");
out.println("<body>");
out.println("<SCRIPT LANGUAGE=\"JavaScript\">");
out.println("javascript:check(this.someVar)");
//System.out.println(someVar);
out.println("</SCRIPT>");
out.println("</body>");
out.println("</html>");
}
}
Thank u
Sanjivani
Malu mathew
Greenhorn

Joined: Nov 01, 2004
Posts: 1
Hai,
Change
out.println("javascript:check(this.someVar)");
to
out.println("javascript:check('"+this.someVar +"')");
U will get the parameter printed.
 
 
subject: parameter passing to Java Script function