0

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

1
  • You have to have a backend to do this. Commented Feb 24, 2015 at 9:57

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thankq madhan, please post an example
1
<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.    -->

2 Comments

Hello, i am using this code $(document).ready(function(){ $('input#receive_count').click(function(event){ var time = $('select#urgent_mail_start_time_year'); load({time: time}); }); function load(dataParams){ $.ajax({ url: '/api/x/shop/receive/get', method: 'get', datatype: 'json', data: dataParams, success: function(html){ alert("in js"); } }); } });
what problem you facing in this code? why you using json?. just call function like load(time);

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.