have another question, to do with ajax and how to send data from a checkbox form without any page reload/redirect, i have the following code, here's the markup:
<html>
<head>
<title>guild</title>
</head>
<body>
<div id="dive">
<form method="post" action="">
<input type="checkbox" name="userList[]" value="together" />together<br />
<input type="checkbox" name="userList[]" value="we" />we<br />
<input type="checkbox" name="userList[]" value="made" />made<br />
<input type="checkbox" name="userList[]" value="it" />it<br />
<input type="submit" id="submit" value="yeah we did it!" />
</form>
</div>
and here's the jquery:
<script type="text/javascript" src="jquery-1.8.0.min (1).js"></script>
<script type="text/javascript">
$(document).ready(function(){
//when the button is clicked
$("#submit").click(function(){
//put the checked data into an array
var userList= $('#dive input[type=checkbox]:checked').serializeArray();
//send the data without page reload/refresh/redirect
$.post("guild.php", {userList: userList},function(userList)
{
});
});
});
</script>
</body>
</html>
so the checked data is supposed to be sent to a php file which writes it to a file, here's the script:
<?php
//get sent data
$userList=$_POST['userList'];
//open file to be written to
$fp=fopen("guild.html", 'a');
//write data into file
for($i=0;$i<sizeof($userList);$i++)
{
fwrite($fp, "<div class='gn'>."userList[$i]"."<br>"."</div>");
}
//close file
fclose($fp);
?>
i know that this is a very simple question, but i just can't get it to work, even after reading other answers. i need the checked data to be sent in form of an array, not a string. so how would i change the jquery part to make it work?thanks in advance for the help, i am an extreme beginner!
array
. – Justin Wood Oct 3 '12 at 17:45