Hello!
I was wondering if I could get some assistance with something that is probably easy for even an amateur javascript coder, but, I just can't seem to get after trying every iteration of code I can imagine.
The deal is, is that I'm trying to put together a PHP search form, with checkboxes for countries (USA, CAN, MEX), and a set of checkboxes for each state in each country, including an "ALL STATES" checkbox for each country.
I'm trying to input form controls where, if someone checks the "ALL STATES" box for any country, it will automatically uncheck any state checkboxes for that country. However, since the checkbox name attributes need to go to PHP as an array, I can't remove the square brackets in the name (I tried escaping the characters with up to 2 backslashes, but that didn't help).
When I tried referring to the checkboxes via getElementById, that also failed. My code for the script as well as the form (abbreviated for convenience and sanity's sake) is below.
If anyone can point out to me where I'm going wrong, I'd appreciate it!
<script language="JavaScript">
<!-- Begin
function Check()
{
var USA_0 = document.getElementById("Search_Origin_State_USA_0");
var USA_1 = document.getElementById("Search_Origin_State_USA_1");
if(USA_0.checked == true)
{
USA_1.checked = false ;
}
else
{
USA_1.checked = true ;
}
}
// End -->
</script>
...and now the form and checkbox fields:
<form action="test.php" method="post" name="load_search" target="_parent">
<input type="checkbox" name="Search_Origin_State_USA[%]" value="%" onClick="Check()" id="Search_Origin_State_USA_0" />
All US States
<input type="checkbox" name="Search_Origin_State_USA[AK]" value="AK" id="Search_Origin_State_USA_1" />
AK</label>