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

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.