Jump to content

need help with checkboxes


doforumda

Recommended Posts

hi, I am trying to use checkboxes with jquery and php. I am submitting checkboxes to php file using jquery. but what I want to do is to get checked checkboxes and send to php file and display all the checked values.

 

Here is my current code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-lib.js"></script>
<script>
$(function() {
$('#submit').click(function() {
	var inp = $('input:checkbox').val();
	//alert(inp);
	var url = 'test1process.php?inp=' + inp;
	$(location).attr('href',url);
});
});
</script>
</head>

<body>
<input type="checkbox" name="checkbox[]" id="checkbox" value="a" />A<br />
<input type="checkbox" name="checkbox[]" id="checkbox" value="b" />B<br />
<input type="checkbox" name="checkbox[]" id="checkbox" value="c" />C<br />
<input type="checkbox" name="checkbox[]" id="checkbox" value="d" />D<br />
<input type="checkbox" name="checkbox[]" id="checkbox" value="e" />E<br />
<input type="checkbox" name="checkbox[]" id="checkbox" value="f" />F<br />
<input type="checkbox" name="checkbox[]" id="checkbox" value="g" />G<br />

<input type="button" name="submit" id="submit" value="Submit" />
</body>
</html>

 

here php file

<?php
$inp = $_GET['inp'];
if(count($inp) > 0) {
for($i = 0; $i < count($inp); $i++) {
	echo "Value:  $inp[$i]<br>";
}
}
?>

please help!

Link to comment
Share on other sites

Yea I know it would be easy but I making these input form fields dynamically using php's echo. this is just demo to get help. here is how i am making that form right now

 

if(!($_SESSION['userid'] && $_SESSION['username'])) {
	header("Location: error.php");
} else {
	echo "<button name='edit' id='edit'>Edit</button>";
	echo "<button name='delete' id='delete'>Delete</button>";
	echo "<button name='addAttorney' id='addAttorney'>Add Attorney</button>";
	echo "<table cellpadding='2' border='0'>";
		echo "<tr>"; //start of the titles row
			echo "<td></td>";
			echo "<td><b>Name</b></td>";
			echo "<td><b>Email</b></td>";
			echo "<td><b>Address</b></td>";
			echo "<td><b>Mobile Number</b></td>";
			echo "<td><b>Validity</b></td>";
			echo "<td><b>Code</b></td>";
		echo "</tr>"; // end of the titles row
	$get_poa = mysql_query("SELECT * FROM permanentattorneyinfo WHERE userid='$_SESSION[userid]'");
	if(mysql_numrows($get_poa) > 0) {
		while($row = mysql_fetch_assoc($get_poa)) {
			$attorneyName = $row['nameOfAttorney'];
			$attorneyAddress = $row['addressOfAttorney'];
			$attorneyMobile = $row['mobileOfAttorney'];
			$attorneyEmail = $row['emailOfAttorney'];
			$validFrom = $row['validFrom'];
			$validTo = $row['validTo'];
			$code = $row['poaCode'];
				echo "<tr class='lightgrey'>"; //start of the data row
					echo "<td><input type='checkbox' name='delete[]' value='$attorneyName' /></td>";
					echo "<td>$attorneyName</td>";
					echo "<td>$attorneyEmail</td>";
					echo "<td>$attorneyAddress</td>";
					echo "<td>$attorneyMobile</td>";
					echo "<td>$validFrom - $validTo</td>";
					echo "<td>$code</td>";
				echo "</tr>"; // end of the data row
		}
		echo "</table>"; //End of table
	} else {
		echo "You do not choose power of attorney yet!";
	}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.