如何从MySQL数据中选择填充选项?

时间:2011-02-17 15:58:35

标签: jquery mysql

如何从MySQL数据中选择填充选项?当选择虚拟选项时,它会很好地填充到textarea。

<html> 
<head> 
<title>Populate Dropdown...NOT</title> 
<link rel="stylesheet" type="text/css" href="load2.css" media="screen"> 
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>

<script type="text/JavaScript"> 
$(function() {
     $('#nameSelect').change(function() {
         $.get('getDetails.php', {name: $(this).val()}, 
            function(data) {
               $('#details').val(data);
            }
         );
     });
});
</script> 
</head> 
<body> 

<div class="right">
<p>
<table border="1" bgcolor="#DDDDDD">    
  <tr>
    <td>Use Existing Asset ID:</td>
    <td><select name="name" id="nameSelect" style="width:95px;">
        <option>Ford</option>
        <option>Chevy</option>
            </select></td>      
    </tr>
    <tr>
      <td>Existing Ticket Status: </td>
      <td><input type="text" size="12" maxlength="36" id="ticket_status"  name="ticket_stat"></td>
    </tr>
    <tr>
      <td>Existing Prob. Desc: </td>
      <td><input type="text" size="12" maxlength="36" id="problem_desc" name="problem_desc"></td>
    </tr>
    <tr>
      <td>Existing Priority Code: </td>
      <td><input type="text" size="12" maxlength="36" id="priority_code" name="priority_code"></td>
    </tr>
</table>
</p>    
</div>

<div id="Div4">
  <textarea id="details" rows="20" cols="40"></textarea>
<div>

</body> 
</html>

1 个答案:

答案 0 :(得分:0)

一种方法是创建一个服务器端ajax函数,它返回结果的json arary,然后为数组中的每个结果$('#yourSelect').append('<option>'+returnedArray[i]+'</option>')