<form action="[[~[[*id]]]]" method="POST"> <p>Select a Projection:</p> <div> <select id="my-select03" name="proj[]" multiple="multiple" onChange="this.form.submit();"> <option value="6" [[+6_selected]]>Proj = 6" < 7"</option> <option value="7" [[+7_selected]]>Proj = 7" < 8"</option> <option value="8" [[+8_selected]]>Proj = 8" < 9"</option> <option value="9" [[+9_selected]]>Proj = 9" < 10"</option> <option value="10" [[+10_selected]]>Proj = 10" < 11"</option> <option value="11" [[+11_selected]]>Proj = 11" < 12"</option> </select> </div> <p>Select a Height:</p> <div> <select id="my-select04" name="height[]" multiple="multiple" onChange="this.form.submit();"> <option value="6" [[+6_selected]]>Height = 6" < 7"</option> <option value="7" [[+7_selected]]>Height = 7" < 8"</option> <option value="8" [[+8_selected]]>Height = 8" < 9"</option> <option value="9" [[+9_selected]]>Height = 9" < 10"</option> <option value="10" [[+10_selected]]>Height = 10" < 11"</option> <option value="11" [[+11_selected]]>Height = 11" < 12"</option> </select> </div> </form>
$proj = array();
if (isset($_POST['proj']) && (!empty($_POST['proj']))) {
$proj = $_POST['proj'];
}
$height = array();
if (isset($_POST['height']) && (!empty($_POST['height']))) {
$height = $_POST['height'];
}
$c = $modx->newQuery('Products');
$projArray = array();
foreach($proj as $s01) {
$projArray[] = array('proj:LIKE' => $s01.'.'.'%');
$modx->setPlaceholder($s01 . '_selected', $selected);
}
$heightArray = array();
foreach($height as $s04) {
$heightArray[] = array('height:LIKE' => $s04.'.'.'%');
$modx->setPlaceholder($s04 . '_selected', $selected);
}
This question has been answered by BobRay. See the first response.
What is your onChange= doing?
onChange="this.form.submit();
array('proj:LIKE' => $s01.'.'.'%')I don't think the values can be the same, what is happening is the user is just re-selecting the value.Thanks, I've considered (and tested) that, but than the problem is how to put that value into an array so I can find the right products. This is what I use now
<option value="6"
Change at least one set of these to 6p or 6h, or change both sets so they are clear.
array('proj:LIKE' => $s01.'.'.'%')Pretty sure I am right about this. The id="my-select03" is not how the data is stored here. The value term is what it goes in the db under. Name value is not as critical, never understood what it is for except adding some data I guess. Messing with what you put in the name="X" doesn't seem to affect anything, its some additional attribute.id="my-select03" is to make the selectbox work properly with jquery.
Your two sets of "selected" placeholders each need a prefix so the code doesn't set both of them at once.This works beautifully!! Thanks Bob!
<form action="[[~[[*id]]]]" method="POST"> <p>Select a Projection:</p> <div> <select id="my-select03" name="proj[]" multiple="multiple" onChange="this.form.submit();"> <option value="6" [[+p6_selected]]>Proj = 6" < 7"</option> <option value="7" [[+p7_selected]]>Proj = 7" < 8"</option> <option value="8" [[+p8_selected]]>Proj = 8" < 9"</option> <option value="9" [[+p9_selected]]>Proj = 9" < 10"</option> <option value="10" [[+p10_selected]]>Proj = 10" < 11"</option> <option value="11" [[+p11_selected]]>Proj = 11" < 12"</option> </select> </div> <p>Select a Height:</p> <div> <select id="my-select04" name="height[]" multiple="multiple" onChange="this.form.submit();"> <option value="6" [[+h6_selected]]>Height = 6" < 7"</option> <option value="7" [[+h7_selected]]>Height = 7" < 8"</option> <option value="8" [[+h8_selected]]>Height = 8" < 9"</option> <option value="9" [[+h9_selected]]>Height = 9" < 10"</option> <option value="10" [[+h10_selected]]>Height = 10" < 11"</option> <option value="11" [[+h11_selected]]>Height = 11" < 12"</option> </select> </div> </form>
$proj = array();
if (isset($_POST['proj']) && (!empty($_POST['proj']))) {
$proj = $_POST['proj'];
}
$height = array();
if (isset($_POST['height']) && (!empty($_POST['height']))) {
$height = $_POST['height'];
}
$c = $modx->newQuery('Products');
$projArray = array();
foreach($proj as $s01) {
$projArray[] = array('proj:LIKE' => $s01.'.'.'%');
$modx->setPlaceholder('p'.$s01 . '_selected', $selected);
}
$heightArray = array();
foreach($height as $s04) {
$heightArray[] = array('height:LIKE' => $s04.'.'.'%');
$modx->setPlaceholder('h'.$s04 . '_selected', $selected);
}