Currently I have one php file createNewForm.php. In it, I have a list of checkboxes, when I check each checkbox, I want the sql query in my php file (createNewForm.php) to repopulate a list.
So lets say I have checkboxes 'Animals', 'Plants', 'Food' and I check 'Animals' then list will populate with Chicken, Cow, Dog. If I check 'Food', it will include 'Chicken','Cow','Dog','Pizza' where 'Chicken' is in both Animals and Food (sorry if you are vegetarian haha).
I am not so much worried about the SQL side of things as that part is working.
Below is my javascript for sending my checked values (Animals,Plants,Food) to itself:
createNewForm.php (javascript portion)
private void MyRectangle_DragOver(object sender, DragEventArgs e)
{
Point p = e.GetPosition(MyRectangle);
if ((p.X > 0) && (p.X < MyRectangle.ActualWidth) && (p.Y > 0) && (p.Y < (MyRectangle.ActualHeight / 2)))
{
Mouse.OverrideCursor = Cursors.UpArrow;
}
else
{
Mouse.OverrideCursor = null;
}
}
createNewForm.php (php portion)
var $checkedSites = [];
var $checkedSitesString = '';
$(document).ready(function() {
$('.checkedSites').change(function() {
if($(this).is(':checked')) {
$checkedSites.push($(this).val());
}
else
{
$checkedSites.splice($.inArray($(this).val(),$checkedSites),1);
}
$checkedSitesString = "'" + $checkedSites.join("','") +"'";
var sitesChosen = 'sitesChosen='+$checkedSitesString;
$.ajax({
type: "GET",
url: "createNewForm.php",
data: sitesChosen,
cache: false,
success: function(result){
alert(result);
}
});
});
});
Currently the output, as the code is written will give me the complete set regardless of which one is checked for sanity purposes. I have also echo'ed the result from my php when it is set through Javascript and my SQL statement is revised to what I want it to be but it also concatenates the entire HTML generated from my php without changing the content on the actual page. In addition this echo, for some reason is generated as an alert, instead of being written to the page.
Thank you!
Norman
答案 0 :(得分:0)
你真的没问过问题。那会很好。
就您的代码所说的警报而言。
alert(result);
相反,如果您需要“写入页面”,请创建一个div以将消息放入。
<强> HTML 强>
<div id="msg"></div>
<强> JS 强>
var msg= document.getElementById('msg);
msg.innerHTML = result;