我正在使用对话框在提交时显示表单和回显消息。这很好用。我还有一个下拉菜单,从中选择值填充第二个下拉菜单。这在它自己很好用,但如果我尝试合并这两个,那么div id =“divId”没有显示或填充更改。现在我将是第一个承认我的jQuery知识至少是基本的,所以我很感激专家的帮助。我已经提供了代码供您注意并等待您的意见。感谢
此代码位于单独的function.js
中// Function to add box
function addbox() {
$("#boxaddform").dialog({
autoOpen: false,
resizable: true,
modal: true,
title: 'Submit a box intake request',
width: 470,
beforeclose: function (event, ui) {
$("#addbox").html("");
}
});
$('#boxsubmit').click(function () {
var box = $('.box').val();
var service = $('#service').val();
var authorised = $('.authorised').val();
var data = 'box=' + box + '&authorised=' + authorised + '&service=' + service;
$.ajax({
type: "POST",
url: "boxesadd.php",
data: data,
success: function (data) {
$("#boxform").get(0).reset();
$('#addbox').html(data);
//$("#form").dialog('close');
$("#flex1").flexReload();
}
});
return false;
});
$("#boxaddform").dialog('open');
}
HTML
<script language="javascript" type="text/javascript">
$(function() {
$("#company").change(function() {
if ($(this).val()!="") $.get("getOptions.php?customer=" + $(this).val(), function(data) {
$("#divId").html(data);
});
});
});
</script>
<!--- Form to add box -->
<div id="boxaddform" style="display:none;">
<form id="boxform" method="post" class="webform" name="boxform" />
<label for="company">Select a Company:</label>
<select name="company" id="company" />
<option SELECTED VALUE="">Select a Company</option>
<?php
do {
?>
<option value="<?php echo $row_Recordsetcust['customer']?>"><?php echo $row_Recordsetcust['customer']?></option>
<?php
}
while ($row_Recordsetcust = mysql_fetch_assoc($Recordsetcust));
$rows = mysql_num_rows($Recordsetcust);
if($rows > 0)
{
mysql_data_seek($Recordsetcust, 0);
$row_Recordsetcust = mysql_fetch_assoc($Recordsetcust);
}
?>
</select><br />
<div id="divId"></div><br />
<label for="service">Enter service level:</label>
<select name="service" id="service">
<option SELECTED VALUE="">Select an option</option>
<option value="Standard">Standard</option>
<option value="Rapid">Rapid</option>
</select>
<br />
<label for="box">Enter a Box#:</label>
<input id="box" name="box" type="text" class="text ui-widget-content ui-corner-all inputbox box" />
<label for="authorised">Requested By:</label>
<input name="authorised" type="text" class="text ui-widget-content ui-corner-all inputbox authorised" id="authorised" value="<?php echo $_SESSION['kt_name_usr']; ?>" /><br />
<div id="addbox"></div>
<button id="boxsubmit" class="submit">Submit</button>
</form>
</div>
getOptions.php
<?php
$customer = mysql_real_escape_string( $_GET["customer"] ); // not used here, it's the customer choosen
$con = mysql_connect("localhost","root","");
$db = "sample";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
$query_rs_select_address2 = sprintf("SELECT * FROM company_com where idcode_com = '$customer'");
$rs_select_address2 = mysql_query($query_rs_select_address2, $con) or die(mysql_error());
$row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2);
$totalRows_rs_select_address2 = mysql_num_rows($rs_select_address2);
echo 'Select delivery address'.'<select name="customeraddress">';
echo '<option value="">Select delivery address</option>';
while ($row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2))
{
$address=$row_rs_select_address2['address1_com']. " ".
$row_rs_select_address2['address2_com']. " ".
$row_rs_select_address2['address3_com']. " ".
$row_rs_select_address2['town_com']. " ".
$row_rs_select_address2['postcode_com'];
echo '<option
value="address">'.$address.'</option>';
}
echo '</select>';
?>
答案 0 :(得分:3)
尝试把这个
$("#company").live('change', function() {
if ($(this).val()!="") $.get("getOptions.php?customer=" + $(this).val(), function(data) {
$("#divId").html(data);
});
});
在您提供的脚本的第一部分中。
我的想法是,更改处理代码可能没有捕获下拉列表而根本没有运行。 为了测试那个put alert('test');在你当前的$(“#company”)里面.change(function(){...});块。