0

I am trying to pass value from one JSP page to another page using jquery.In below code I would like to pass the variable "processId" to another page. The value should pass to another page after the below JSP page is loaded.

I am getting error: "procId is undefined"

<head>
<script type="text/javascript" src="jqwidgets/scripts/jquery-1.8.1.min.js"></script>

<script type="text/javascript">
window.onload=passValue;
function passValue()
{
$.post("Testing.jsp", {processId: ""+procId+""});
}
</script>
</head>
<%
String processId = "555";
%>
<form name="fm" id="fm">
<input  type="hidden" id="procId" value="<%=processId%>" name="processId">
</form>
</html>
1
  • JSP files are supposed to be invoked only by Servlets (MVC). Are you sure you want to call them directly from the browser? Commented Oct 10, 2012 at 9:15

2 Answers 2

2

not sure. but you can try the following

$.post("Testing.jsp", {"processId": ""+$("#procId").val()+""})
Sign up to request clarification or add additional context in comments.

Comments

0

jQuery calls should be placed within the standard block:

$(document).ready(function(){
    //jQuery code here
});

With this block, the code won't execute until the DOM is fully loaded; you don't need to assign a function to window.onload. 

Next, to grab the value of the input with id "procId", you need to create a jQuery object using the regular syntax: $('#procId'), then access its value with .val()

So this should do it:

$(document).ready(function () {
    $.post("Testing.jsp", {"processId": $("#procId").val() })
});

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.