Jump to content

html onCheck checkboxes in PHP


prometheos

Recommended Posts

Hi,

i have 2 arrays of checkboxes and i want it so that when i check 1, the same index of the other 1 is unchecked...

any ideas how to do this?

here's the way i have it set up?

 

	if(($xml->item[$n-1]->requested->confirmed == "") &&($xml->item[$n-1]->requested->by != "") ){			
			echo '<td><center><input type="checkbox" name="confirmItems[]" value="'.$itemString.' onCheck = " " "/></center></td>';
			echo '<td><center><input type="checkbox" name="denyItems[]" value="'.$itemString.'"/></center></td>';
		}

 

What should i do in the onCheck?

this is inside a foreach loop by the way.

thanks for the help :) 

Link to comment
https://forums.phpfreaks.com/topic/196486-html-oncheck-checkboxes-in-php/
Share on other sites

I don't know why you are using an array to define the checkboxes, but that is the fist change I'd make:

 

<input type="checkbox" name="confirmItems" value="'.$itemString.' onCheck = " " "/>

 

Then I'd take into consideration that not all browsers will display the value="" portion:

 

<input type="checkbox" name="confirmItems[]" value="'.$itemString.' onCheck = " " ">'.$itemString.'</input>

 

Then the javascript you need would look like:

 

<script language="javascript">
function uncheck(src,element)
{

if (src.checked==true)
{
element.checked=false
}
}
</script>

<form name="request">
<input type="checkbox" name="confirm" onClick="uncheck

(this,document.request.deny)">confirm</input>
<input type="checkbox" name="deny" onClick="uncheck(this,document.request.confirm)">deny</input>
</form>

[code]

I didn't bother to convert this into php, so when you copy and paste put it into a htm file and then make the mods to get it going in php.  The only difference between this and a radio object is that once you select one, you can make the decision to clear both--if this is not the behavior you want look into the radio object.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.