As shown in the figure:
This is a table with select in it. Now we have obtained a string about the values of all drop-down menus.
I want to cut them into separate data and store them in an array. I have no idea at the moment. Please give me some ideas = =
**
**
The string obtained is: "Year-end final settlement 2005 approved collection and prepayment - monthly 2016 please select audit collection and prepayment - quarterly 2008 fourth quarter approved collection".
In other words, all the values selected by select are connected together, and I have no idea of cutting them apart.
Finally I want to make it
[{type:"年终汇算",time1:"2005年",time2:"",fangs:"核定征收"},{type:"预缴-月度",time1:"2016年",time2:"2月",fangs:"查账征收"},{type:"预缴-季度",time1:"2008年",time2:"第四季度",fangs:"查账征收"}]
This is what I want to save in the end.
**
**
Among these options, if the user does not choose, "Please select" will be displayed. How can we judge whether "Please select" appears in these values? (In other words, you cannot submit without selecting it. You must select every option before you can submit the storage data).
PS: 1. My annual and monthly quarter options are different. The top one is the second level linkage, and the bottom monthly quarter is the third level linkage
2. My selection is written in the trtd of the table, and These are dynamically generated with an "Add" button.
I'm sorry I forgot to mention these two points just now, I'll add a few more -.-
1. It is strongly not recommended to use segmentation. You should find a way to optimize the "get selected" items so that these fields are naturally structured.
If you use the segmentation method, the maintenance cost will be very high in the future.
2. In the form submission code, obtain the value of each option in turn and judge the legality. In fact, this is also a common approach.
Drop-down selection and value ideas
The following are my thoughts
Each row instance has a
value
object, like:this.value = {}
;The
select
in the line uses standard numeric values to compare the array subscripts to ensure the accuracy of the value;Every
change
event ofselect
will modify a corresponding value, such as: when the firstselect.type
is selected, addthis.value.type = $type[0] before the linkage code. value
—— Substitute the corresponding variable by yourself;Use hidden fields to manage output, such as:
<input type="hidden" name="name[]" />
;You can use any data format. I personally recommend using numbers as much as possible, such as:
The last
select.fangs
will generate available data for use by the form when selecting, such as:About verification
Extend a validation method, such as:
AppRow.prototype.validate()
. This method monitors the legality of the form based on the content ofthis.value
and returns a Boolean value, such as:Is it an empty object first? If so, it means that the first
select
in this row isPlease select
and returnfalse
;If
.type - 0 - Annual Calculation
(the firstselect
) is selected, get theAppRow.typeChose[this.value.type]
object;The object does not exist, indicating that it may be out of bounds. If it does not exist at all,
AppRow.typeChose[4]
, returnsfalse
;According to the selected
AppRow.typeChose[this.value.type].types
, it is obtained thattypeSubLen
is the number of subsequent forms corresponding to the current type, that is, the current type should have several related children;If
(this.value.length - 1) < typeSubLen
indicates insufficient length, missing parameters, or!this.value.time1
does not exist, returnfalse
;this.value.time1
exists, value=== -1
or!AppRow.typeChose[0].types[this.value.time1]
, returnsfalse
;this.value.time2
exists, the value=== -1
or!AppRow.typeChose[0].types[0].zType_time1[this.value.time1]
, returnsfalse
;!this.value.fangs
orthis.value.fangs === -1
, returnsfalse
;If all conditions are met, return
true
;