Page 1 of 1
[56K WARN] Post Check box value
Posted: Mon Nov 20, 2006 5:26 am
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'
Posted: Mon Nov 20, 2006 9:24 am
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>
Posted: Tue Nov 21, 2006 5:50 am
by tharange
feyd | Please use 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
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]
Posted: Tue Nov 21, 2006 6:11 am
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?
Posted: Thu Dec 07, 2006 1:51 am
by tharange
Finaly I Failed
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....