开发者

How do I get an option select to populate from MySQL data?

开发者 https://www.devze.com 2023-02-10 21:51 出处:网络
How do I get an option select to populate from MySQL data? It populates to a textarea just fine when a dummy option is selected.

How do I get an option select to populate from MySQL data? It populates to a textarea just fine when a dummy option is selected.

<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>
        <opti开发者_运维百科on>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>


One way is to create a server side ajax function that returns a json arary of results, then for each result in the array you need to $('#yourSelect').append('<option>'+returnedArray[i]+'</option>')

0

精彩评论

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

关注公众号