[56K WARN] Post Check box value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tharange
Forum Newbie
Posts: 5
Joined: Mon Nov 20, 2006 5:06 am

[56K WARN] Post Check box value

Post by tharange »

Hi,

On my email program, I have list of headers of new Emails. when I click 'Delete' , programm has to POST the values of checked checkboxes to delete them after confirmation.

Please tell me is there any way to detect the values of checkboxes and post them to another page.

I feel it should be a function that I can call 'on click' the button 'Delete'
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

checkboxes "ship" like any other input control, as name=value pair.
If they are checked when the form is submitted their name and current value are sent to the server where php can process them.

Code: Select all

<html>
	<head>
		<title>checkbox test</title>
	</head>
	<body>
<?php	
if ( isset($_POST['xyz']) && is_array($_POST['xyz']) ) {
	foreach( $_POST['xyz'] as $xyz ) {
		echo '		checkbox value: ', (int)$xyz, "<br />\n";
	}
}
?>
		<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<div>
				1 <input type="checkbox" name="xyz[]" value="1" /><br />
				2 <input type="checkbox" name="xyz[]" value="2" /><br />
				3 <input type="checkbox" name="xyz[]" value="3" /><br />
				4 <input type="checkbox" name="xyz[]" value="4" /><br />
				5 <input type="checkbox" name="xyz[]" value="5" /><br />
				<input type="submit" />
			</div>
		</form>
	</body>
</html>
tharange
Forum Newbie
Posts: 5
Joined: Mon Nov 20, 2006 5:06 am

Post by tharange »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thanks for the post. 

But in my case 'Checkboxes' are extremely seperate from the 'DELETE BUTTON'.

I'm unable to put all Checkboxes and Submit Button together in a form tag as you've done.

Some thing like this.

[syntax="html"]<script language="javascript">
function sec() {
var myFormsLen = document.formName.elements.length;
for(i=0; i<myFormsLen; i++) {
if(document.formName.elements[i].type == 'checkbox' &&
document.formName.elements[i].checked) {
alert(document.formName.elements[i].nextSibling.data);
}
}
}
</script>

<button onclick="sec();">button</button>

<form name="formName">
<label><input type="checkbox">1111</label><br>
<label><input type="checkbox">2222</label><br>
<label><input type="checkbox">3333</label><br>
<label><input type="checkbox">4444</label><br>
<label><input type="checkbox">5555</label><br>
</form> 
With this code, I can have a massage with Cbox value or name. But I need to Post them. If you can edit above function for my purpose, Its also OK.

Thanks.


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

assign an attribute id to the form element.
In your javascript function fetch the form object vie document.getElementById.
Invoke submit() on that object.

--
why can't you add a submit element to the form?
tharange
Forum Newbie
Posts: 5
Joined: Mon Nov 20, 2006 5:06 am

Post by tharange »

Finaly I Failed

Image

Tell me a way to post checked CB's value (under Test colom) to another page when I click DELETE (on bottom in black).

Example please....
Post Reply