Reputation: 332
I have a Button and a function which displays some data. I want to call the function on button click. The data needs to be displayed on the same page. I don't want a page forward. And also want to avoid JavaScript. What should I do? Here is the code-
<form >
Number of jobs: <select name="jobs">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
</select><br>
Number of PE:<select name="process">
<option value="2">2</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
</select>
<input type=submit value="Submit" onClick=check(x,y)>
</form>
</text1>
void check(int x, int y)
{
<jsp:include page="table" >
<jsp:param name="jobs" value=x/>
<jsp:param name="process" value=y/>
</jsp:include>
}
I want to call the function check() on button click(submit). Plus I want to send the values selected in the dropdown list as arguments to the function.
Upvotes: 2
Views: 3978
Reputation: 14877
I dont want a page forward. And also want to avoid javascript.
I think opting out both can't be possible.
You use jQuery/Ajax
call to display data on the same page without submitting it.
Example:
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
function getData() {
var dataToBeSent = {
param1 : $("#jobs").val() ,
param2: $("#process").val()
}; // you can change parameter name
$.ajax({
url : 'getDataServlet', // Your Servlet mapping or JSP(not suggested)
data :dataToBeSent,
type : 'POST',
dataType : 'html', // Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.
success : function(response) {
$('#outputDiv').html(response); // create an empty div in your page with some id
},
error : function(request, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
});
HTML From Your Example:
Number of jobs: <select name="jobs" id="jobs">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
</select><br>
Number of PE:<select name="process" id="process">
<option value="2">2</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
</select>
<input type=submit value="Submit" onClick=getData();>
Upvotes: 1