Reputation: 14741
I am new to Jquery and I am using Jquery to populate values in a drop down field.
Upon selection of a value from drop down, I am assigning value to a hidden field.
onSelect: function(index,row){
var val = row.value;
alert('val '+val );
$("#hid").val(val );
}
How can I assign the value to JSP variable or if I use request.getParameter("hid");
do I need to submit the form again to get the value?
Edit 1
$(function(){
$('#comb').combogrid({
panelWidth:200,
url: 'myservice',
idField:'id',
textField:'desc'
columns: [[
{field:'Id',title:'Id',width:20},
{field:'desc',title:'Desc',width:80}
]],
onSelect: function(index,row){
var val = row.value;
alert('val '+val );
$("#hid").val(val );
}
});
});
Upvotes: 0
Views: 12014
Reputation: 195
JSP is Java code which runs on your server side.
JavaScript runs on your browser.
So you cannot assign JSP variables using JavaScript.
Form submit or ajax is the right choice for this situation.
Ajax Code snippet.
onSelect: function(index, row) {
$.ajax({
url: '/your-url', // path to your url which gets this ajax request
method: 'get', // or a http method you want to use
data: {
value: row.value
},
success: function(response) {
alert('Boom!' + response);
}
});
}
See jQuery Ajax API docs for more information. There are lots of options.
Upvotes: 5
Reputation: 3673
Based on user's selection of the dropdown, if you want to do someting on the server side, I would suggest to send AJAX call or Form submit.
You wont be able to do the below directly.
request.getParameter("hid");
Upvotes: 1