I've scoured all over the net to find out any help I can to try to get this to work. Currently I have a list of checkboxes like this...
***
<table width="610">
<tr>
<td width="25%">
<Form name="advanced" align="left" action="<?php
echo $_SERVER['PHP_SELF'];
?>">
<input type="checkbox" name="list[]" value="bedroom"/>
Bedroom Suites<br/>
<input type="checkbox" name="list[]" value="upholstery"/>
Upholstery<br/>
<input type="checkbox" name="list[]" value="dining"/>
Dining Room<br/>
<input type="checkbox" name="list[]" value="entertainment"/>
Entertainment<br/>
<input type="checkbox" name="list[]" value="office"/>
Office<br/>
</td>
<td width="75%">
<input type="checkbox" name="list[]" value="occasionals"/>
Occasionals<br/>
<input type="checkbox" name="list[]" value="youth"/>
Youth<br/>
<input type="checkbox" name="list[]" value="futons"/>
Futons/Bunkbeds<br/>
<input type="checkbox" name="list[]" value="waterbeds"/>
Waterbeds<br/>
<input type="checkbox" name="list[]" value="misc"/>
MISC.<br/>
</td>
</tr>
<input type="button" value="Check All" onClick="this.value=check(document.advanced.list)" method="get">
</td></tr>
***
I was told that the name needed to have the brackets at the end so PHP could increment the names and thus have different variables instead of one array.
Here is the submit form button...
<input type="submit" method="post" onClick="this.value=checkbox_checker(document.advanced.list)" name="phpselector" value="Search" />
And here is the javascript that I'm using that is pulled from file...
***
var checkflag = "false";
function check(field)
{
if (checkflag == "false")
{
for (w = 0; w < field[w].length; w++)
{
field[w].checked = true;
}
checkflag = "true";
return "Uncheck All";
}
else
{
for (w = 0; w < field[w].length; w++)
{
field[w].checked = false;
}
checkflag = "false";
return "Check All";
}
}
function checkbox_checker(fielda)
{
// set var tabletest to false
var tabletest = false;
// Loop from zero to the one minus the number of radio button selections
for ( q = 0; q < fielda[q].length; q++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (fielda[q].checked)
tabletest = true;
}
if (!tabletest)
{
// If there were no selections made display an alert box
alert("Please Select a department to search in")
return false;
}
return "Verified";
}
***
As I'm sure you guessed, this is for a furniture website.
This is part of the advanced search form. Basically, I want customers to be able to check one or all of the departments (actually tables) that they want to search in, and then type in whatever search criteria they want. Each checkbox corresponds to a table name which will be passed via the URL to the same page that will then be used in the query to find results.
It all works fine if I take the brackets off the list[] name in the form and leave the javascript as something like field.length (instead of field[w].length), but it seems like it all is listed under the same name.
When I use the brackets, javascript apparently doesn't like that.
I'm a bit rusty on my javascript, and green with PHP. The code you see above is my latest brain fart at an attempt to trial and error my way to a solution. I have since determined I may require the assistance and expertise of some higher powers.
Thank you for any help or direction anyone can offer.
***
<table width="610">
<tr>
<td width="25%">
<Form name="advanced" align="left" action="<?php
echo $_SERVER['PHP_SELF'];
?>">
<input type="checkbox" name="list[]" value="bedroom"/>
Bedroom Suites<br/>
<input type="checkbox" name="list[]" value="upholstery"/>
Upholstery<br/>
<input type="checkbox" name="list[]" value="dining"/>
Dining Room<br/>
<input type="checkbox" name="list[]" value="entertainment"/>
Entertainment<br/>
<input type="checkbox" name="list[]" value="office"/>
Office<br/>
</td>
<td width="75%">
<input type="checkbox" name="list[]" value="occasionals"/>
Occasionals<br/>
<input type="checkbox" name="list[]" value="youth"/>
Youth<br/>
<input type="checkbox" name="list[]" value="futons"/>
Futons/Bunkbeds<br/>
<input type="checkbox" name="list[]" value="waterbeds"/>
Waterbeds<br/>
<input type="checkbox" name="list[]" value="misc"/>
MISC.<br/>
</td>
</tr>
<input type="button" value="Check All" onClick="this.value=check(document.advanced.list)" method="get">
</td></tr>
***
I was told that the name needed to have the brackets at the end so PHP could increment the names and thus have different variables instead of one array.
Here is the submit form button...
<input type="submit" method="post" onClick="this.value=checkbox_checker(document.advanced.list)" name="phpselector" value="Search" />
And here is the javascript that I'm using that is pulled from file...
***
var checkflag = "false";
function check(field)
{
if (checkflag == "false")
{
for (w = 0; w < field[w].length; w++)
{
field[w].checked = true;
}
checkflag = "true";
return "Uncheck All";
}
else
{
for (w = 0; w < field[w].length; w++)
{
field[w].checked = false;
}
checkflag = "false";
return "Check All";
}
}
function checkbox_checker(fielda)
{
// set var tabletest to false
var tabletest = false;
// Loop from zero to the one minus the number of radio button selections
for ( q = 0; q < fielda[q].length; q++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (fielda[q].checked)
tabletest = true;
}
if (!tabletest)
{
// If there were no selections made display an alert box
alert("Please Select a department to search in")
return false;
}
return "Verified";
}
***
As I'm sure you guessed, this is for a furniture website.
This is part of the advanced search form. Basically, I want customers to be able to check one or all of the departments (actually tables) that they want to search in, and then type in whatever search criteria they want. Each checkbox corresponds to a table name which will be passed via the URL to the same page that will then be used in the query to find results.
It all works fine if I take the brackets off the list[] name in the form and leave the javascript as something like field.length (instead of field[w].length), but it seems like it all is listed under the same name.
When I use the brackets, javascript apparently doesn't like that.
I'm a bit rusty on my javascript, and green with PHP. The code you see above is my latest brain fart at an attempt to trial and error my way to a solution. I have since determined I may require the assistance and expertise of some higher powers.
Thank you for any help or direction anyone can offer.