user1710288
user1710288

Reputation: 427

passing values using jquery or ajax to another page

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>

Upvotes: 0

Views: 3735

Answers (2)

Faust
Faust

Reputation: 15394

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() })
});

Upvotes: 0

Rohini Kumar
Rohini Kumar

Reputation: 249

not sure. but you can try the following

$.post("Testing.jsp", {"processId": ""+$("#procId").val()+""})

Upvotes: 2

Related Questions