开发者

For onchange of the Dropdown list fetch the data from the db with out submitting the form in php

For onchange of the Dropdown list fetch the data from the db with out submitting the form.

I need to check the data according to the selected data of Dropdown list with database(example: select count(*) from employee).

That is, Consider Dropdown List has 3 options. if User selects 2nd option then, function(method) should be called to get the data from the database. if the Query returns 10 the i need to show some message开发者_StackOverflow中文版. but the form should not submity here, until he clicks the submit button.


You can use JavaScript here to post data to server and return response. For example you can use jQuery .alax() method when the onchange event of your dropdown is fired.

$('#select').change(function(){
  $.ajax({
    url: 'http://domain.name/somescript.php',
    data: {item: $this.find('option:selected').val()}
    success: function(xhr){
      // analyze recieved data from server
      if(xhr.responseText == '10')
        alert('some message');
    }    
  });
});


You need to fire off an XHR request to a script that would query the DB and return the results for you to display. Using jQuery to do it is simple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜