I'm creating an HTML form that displays a column of checkboxes, click on submit and the event will be picked up by a jQuery function. However, after examining the function in the Firebug net panel, I've noticed that the function fires multiple times even if I click the button just once! Any idea why?
HTML:
echo "<form id='massHoursSubtraction'>";
echo "How many hours to subtract? <input type='text' name='hours'><br />";
$entries = 1;
while($row = mysql_fetch_array($members)) {
$studentID = $row['studentid'];
echo "<input type='checkbox' name='studentID[]' id='' value='$studentID'>$studentID";
echo "<br />";
$entries++;
}
echo "<input type='button' id='submitValues' value='Submit' onclick='javascript:getHours($entries);' />";
echo "</form>";
Javascript:
function getHours(numberOfEntries) {
$(document).ready(function() {
$("#submitValues").click(function(){
var str = $("#massHoursSubtraction").serialize();
alert("How many times?");
$.post("output.php", str);
});
});
}
Here's a screenshot of the Firebug net panel: http://imgur.com/Z83s5fr
This is the $_POST string: hours=1&studentID%5B%5D=5112244