Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Auto Submits 1

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
On one site, I have a form that both allows multiple selections and it submits automatically. This is a dynamic form selector, generated in PHP, used for building a database query. However, identical code (as far as I can tell) on another site submits only a single value at a time for some reason and doesn't seem to allow for multiple selections. I realize that it will probably submit with each choice and it "remembers" the selection when making one but then loses it when I hold the CTRL and select another. If I choose a different selector (there are six of them) it loses the previous choices. Any ideas to get it working?

In this sample, for clarity only the first one is populated.

Code:
<p>Select Values:<br>
<select name="Value1[]" id="Value1[]" class="SelectBox" onchange='this.form.submit()' multiple size="5">
<option value="">Value 1</option>
<option value="2007.11.06">2007.11.06</option>
<option value="2008.01.14">2008.01.14</option>
<option value="2008.09.18">2008.09.18</option>
<option value="2008.10.27">2008.10.27</option>
<option value="2008.11.14">2008.11.14</option>
<option value="2008.11.17">2008.11.17</option>
<option value="2008.12.12">2008.12.12</option>
<option value="2008.12.23">2008.12.23</option>
<option value="2009.01.13">2009.01.13</option>
<option value="2009.01.19">2009.01.19</option>
</select><select name="Value2[]" id="Value2[]" class="SelectBox" onchange='this.form.submit()' multiple size="5">
<option value="">Value 2</option>
</select><select name="Value3[]" id="Value3[]" class="SelectBox" onchange='this.form.submit()' multiple size="5">
<option value="">Value 3</option>
</select><select name="Value4[]" id="Value4[]" class="SelectBox" onchange='this.form.submit()' multiple size="5">
<option value="">Value 4</option>
</select><select name="Value5[]" id="Value5[]" class="SelectBox" onchange='this.form.submit()' multiple size="5">
<option value="">Value 5</option>
</select><select name="Value6[]" id="Value6[]" class="SelectBox" onchange='this.form.submit()' multiple size="5">
<option value="">Value 6</option>
</select>
 
not sure I understand totally... but ... if you want to be able to select more than one choice in a dropdown, you need to set the multiple property of the select which in your example is not set.

Code:
<select multiple="multiple">
...
</select>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
I tried both [bold]multiple="multiple"[/bold] and just [bold]multiple[/bold] but neither work when the field is set to auto-submit. It needs to both allow multiple submits and to auto-submit when selected AND it needs to remember its selections so that the next select box in the same form can add to the results when it autosubmits.
 
Its kind of hard to select multiple options when each selection is triggering the submission. It essentially cuts the process. Is it really necessary to submit on selection? Perhaps it would be better to submit on blur once all selections have been made.

If you really need to submit on each selection, and preserve the selections( which is going to be quite annoying if the connection lags for any reason), you'll need to use PHP to dynamically build the select box while checking the POST vars to get the selected options so you can mark them as selected when the page reloads.

Alternatively perhaps Ajax can be better used here to get the desired effect without reloading the page each time.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
Well, it doesn't necessarily need to submit the instant something is selected but it should do it before the user goes to the next sequential select box because their choices in one determines their choices in the next. There are twelve select boxes in two rows of six with the upper single-select one populating the multiple-selct one immediately below it. (This is an Intranet site so lags will hopefully not be an issue.)

I know virtually nothing about Javascript so would onblur submit it once the selections have been made? PHP is already remembering the selection but it remembers only one because additional selections deselect themselves on auto-submit. I had thought of JQuery and Ajax and tried it but unfortunately this need was a last-minute change by the engineering team and I do not have time left in the contract to learn a new technology. Ideally all twelve of these select boxes would be dependant on choices in the previous select box but I am trying to settle for only the second row doing so.
 
In that case, you'll be better off using the onblur event rather than onChange. that way you can select all your choices and when you attempt to leave thew dropdown it will submit the form with the selected options.

Code:
<select name="Value1[]" id="Value1[]" class="SelectBox" [b][COLOR=#204A87]onblur[/color][/b]='this.form.submit()' multiple size="5">

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
That seems to be okay as far as the convenience is concerned (I would prefer immediate submit though!) but the select box is remembering only the very first item in it even if it was not one that was selected. I'll have to revisit the PHP now that it allows multiple choices to see what's wrong. If I make only a single selection, it remembers it without any problem although it disappears below view when it would be better if it were to remain within the viewable area of the select box, which is limited to only five lines to keep it from growing too large.
 
As far as i can tell, the not scrolling to the first selected option is an IE quirk. FF and Chrome both scroll the select to bring into view the first selected option.

Other than that, yes, you'll need to check how you are running through the selections and setting the "selected" property in your PHP code.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
I suspected as much about IE . . . As for the "selected" property, it is working as it selects a single choice so I'm not sure what I can do to make it select multiple choices. I'm still looking at it to see. Thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top