0

I have an sql database and an html form. I want to be able to automatically change the value in a checkbox when a radio button value changes. Here is some partial code with details in red as to what I want to do: (the red text is not actually a part of my code)

<table width="100% border="0">
	<tr>
	<td width="50%" height="25">Status:</td>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Ray" <?php if($data2['Status'] == "Ray"){echo 'checked="checked"';}?> />Ray</td>
	</tr>
	<tr>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Press" <?php if($data2['Status'] == "Press"){echo 'checked="checked"';}?> />Press</td>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Press:MO" <?php if($data2['Status'] == "Press:MO"){echo 'checked="checked"';}?> />MO</td>
	</tr>
	<tr>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Press:GTO|1-color" <?php if($data2['Status'] == "Press:GTO|1-color"){echo 'checked="checked"';}?> />GTO|1</td>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Press:GTO|2-color" <?php if($data2['Status'] == "Press:GTO|2-color"){echo 'checked="checked"';}?> />GTO|2</td>
	</tr>
	<tr>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Press:ABDick|1-color" <?php if($data2['Status'] == "Press:ABDick|1-color"){echo 'checked="checked"';}?> />AB|1</td>
	<td width="50%" height="25"><input type="radio" name="Status" onclick change $data2['Entered'] to unchecked value="Press:ABDick|2-color" <?php if($data2['Status'] == "Press:ABDick|2-color"){echo 'checked="checked"';}?> />AB|2</td>
	</tr>
</table>
	<td>Entered: THIS IS THE CHECKBOX THAT WILL CHANGE <input name="Entered" id="Entered" type="checkbox" value="Y" <?php if($data2['Entered'] == "Y"){echo 'checked="checked"';}?> />
</td>

Could you please help me on what code to use (including the correct quotations, etc.) that I would need to perform this. In the end product, I only want the checkbox to change under certain conditions but I think I would be able to figure that out once I got the basic codes figured out. For example, if the first letter of the "value" changes (I have other radio buttons with other values besides what I posted) then the checkbox would become unchecked, otherwise it would stay checked.

Or would it be easier, rather than entering the onclick event in each radio button (there are lots more than what is listed), to somehow test with variables if the Status has changed and then change the checkbox accordingly. For example, put the Status value into a variable when the form is populated then if the Status is different when it is posted it will then change the checkbox to null before it is posted. I would like to get visual feedback in the form if possible that the checkbox has changed rather than just changing it behind the scenes as the record is being posted.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by diafol
0

You cannot do that in PHP without submitting the form, which would be an awkward user experience.
Use JavaScript instead. Write a function which sets the one checkbox which changes "automatically" and call this function from the onclick events.
And do yourself a favour and generate your repeating HTML code from PHP instead of coding numerous error-prone repetitions.

0

This is javascript not php. You'll need an event handler.

//damn smant another simultaneous post!

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.