0

I have the same query as. Pass a JSP variable as parameter to javascript function However, If i use onclick="pagetype('<%=uname%>'); i'm getting illegal start of type error. Please help to fix this.

Yes.. <%@ page contentType= "text/html" pageEncoding="UTF-8" %>

2 Answers 2

0

Have you put the end double quote?

onclick="pagetype('<%=uname%>')"

The error is a javascript error ? If it is, Is <%=uname%> visible in the page source?

Have you put something like <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> at the top of the jsp?

Sign up to request clarification or add additional context in comments.

6 Comments

Yes.. <%@ page contentType= "text/html" pageEncoding="UTF-8" %>
<%@ page language="java" contentType= "text/html" pageEncoding="UTF-8" %>
<%@ page language="java" contentType= "text/html" pageEncoding="UTF-8" %> <%@ page import =="java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%> <%@page import= "java.util.concurrent.TimeUnit" %> <%@ include file="dbconnect.jsp" %> <html> <% --Connection to db-- while (rsp.next()){String date1 = rsp.getString("p");out.println(date1)}%> <body><form action="" method="post" onsubmit="alert2('<%=date1');"> </html>
<script>function alert2(getid){ var id=get id; window.alert(id);}</script>
If I'm passing some sting instead of <%=date1%> its working fine.
|
0
  1. String date1 is inside a loop. You won't be able to get its value outside.
  2. change alert2('<%=date1'); to alert2('<%= date1 %>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.