i'm Sanjeev My webpage has a button (not submit button of form) inside form. On click of that button i have to run a SQL query and then set other form field on the basis of query result.
My problem is how to run SQL query from javascript
i'm Sanjeev My webpage has a button (not submit button of form) inside form. On click of that button i have to run a SQL query and then set other form field on the basis of query result.
My problem is how to run SQL query from javascript
you have to use ajax script to achieve this process. on button click ajax script is executed and the result is fetched in ajax response then you have to append the results to other form fields.
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function getResult(){
var x=document.getElementById('inp').value;
dat='param=' + x;
$.ajax({
type: "POST",
url: "server.jsp",
data: dat,
cache: false,
success: function(html) {
$('#textdiv').val(html.trim());
}
});
}
</script>
</head>
<body>
<input type="text" name="inp" id="inp">
<button onclick="getResult();">
<input type="text" name="result" id="textdiv">
</body>
<!-- You need server page to execute query and in php the result is echoed.it came back to ajax response inside success function. -->