Prob with Checkbox

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

Prob with Checkbox

Post by tharange »

Jcart | Removed image tags because image isn't really neccesary, and we want to be considerate to 56k users

http://mail.cinec.org/FinalUpload/WEBFi ... delete.jpg

I'm in a big trouble, Please help.

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

Note.. Do not post this.

Code: Select all

<form methord=post..........>
<input type=checkbox name=cb1>
.....
<submit button.........>
</form>
Cos my Checkboxes are unable to gather in to a form tag. Please try to understand the picture.
its an Email box and I need to post checked cb's value and delete messages related to posted cb's value.


thankz
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Could you explain more clearly please.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

1. Rewrite the page so that the checkboxes are all in one form. It's the most sensible approach.

2. Use javascript. getElementsByTagName() is your friend.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Use Check boxes Like This

Code: Select all

<form name="formname">
.......................................
<input type="checkbox" name="chk_field" value="val1" />
<input type="checkbox" name="chk_field" value="val2" />
......................................
</form>
And Use An Another Hidden Field To Hold The Values of Checked Field

Code: Select all

.................................
<input type="hidden" name="hld_chk_field" value="" />
.......................................
And Execute This Function Just before Posting To Store The Checked Vlaues To That Hidden Field Separated By Comma And Post The Value Of That Hidden Field

Code: Select all

function pass_val()
{
	for(i=0;i<=document.formname.chk_field.length;i++)
	{
		if(document.formname.chk_field[i].checked)
		{
		var hld_val = document.getElementById("hld_chk_field").value;
		hld_val += document.formname.chk_field[i].value + ",";
		}
	}
}
And If You Cant Put All The Check Boxes In The Same Form Put Each Check Boxes In Different Forms And Dont Give An Name To Those Forms Keep The Same Name For All The Check Boxes Suppose chk_field
Then Execute This Function before Posting

Code: Select all

function pass_val_diff()
{
	for(i=0;i<=document.forms.length;i++)
	{
		if(document.forms[i].chk_field.checked)
		{
		var hld_val = document.getElementById("hld_chk_field").value;
		hld_val += document.forms[i].chk_field.value + ",";
		}
	}
}
After Post The Data To A Different File To get The Value Of That Hidden Field.
After You Get That Value explod() It To Convert It To an Array.
tharange
Forum Newbie
Posts: 5
Joined: Mon Nov 20, 2006 5:06 am

Post by tharange »

Wow, Thanks man. Thank you all.
Post Reply