1

Topic: Synchronization of two .

Good afternoon, colleagues!
Your help is necessary.
In general there are two , they in general that different, one CONTRACTS, other TYPE of ACTIVITY.
But at them some values identical ' the Sick-list ', ' Business trip ', ' Holiday ', ' Holiday without the content ', ' Social holiday '.
And in case of a choice of one of these values in one , it is necessary to select the same from other.
Here an example of my decision.
In a general view works normally but after I pierce contents we tell time 10, the code starts to work not correctly.
For example at a choice ' the Sick-list ' sometimes reacts not as I expect

var contractChange = 1;
var employmentChange = 1;
$(function () {
$(document).on ("click", "#ContractID", function (e) {
var contractValue = $ ("#ContractID option:selected").text ().trim ();
if (contractChange == 1 && (
contractValue == ' the Sick-list ' ||
contractValue == ' Business trip ' ||
contractValue == ' Holiday ' ||
contractValue == ' Holiday without the content ' ||
contractValue == ' Social holiday '))
{
employmentChange = 0;
$(' select [name = "EmploymentID"] option ').each (function () {
if ($ (this).attr (' selected ') == ' selected ') {
$(this).attr (' selected ', null);
}
})
$(' select [name = "EmploymentID"] option ').each (function () {
if ($ (this).text ().trim () == contractValue) {
$(this).attr (' selected ', ' selected ');
}
})
employmentChange = 1;
}
})
})
$(function () {
$(document).on ("click", "#EmploymentID", function (e) {
var employmentValue = $ ("#EmploymentID option:selected").text ().trim ();
if (employmentChange == 1 && (
employmentValue == ' the Sick-list ' ||
employmentValue == ' Business trip ' ||
employmentValue == ' Holiday ' ||
employmentValue == ' Holiday without the content ' ||
employmentValue == ' Social holiday ')) {
contractChange == 0;
$(' select [name = "ContractID"] option ').each (function () {
if ($ (this).attr (' selected ') == ' selected ') {
$(this).attr (' selected ', null);
}
})
$(' select [name = "ContractID"] option ').each (function () {
if ($ (this).text ().trim () == employmentValue) {
$(this).attr (' selected ', ' selected ');
}
})
contractChange = 1;
}
})
})

Already reached such perversions, with change flags.
Progress in a solution of a problem is not present.
Help .

2

Re: Synchronization of two .

vadipok;
Very strange decision from the point of view of design. That looks logical for the developer never smells even as a hint on any logic at the normal ordinary user.
And it seems that here it is necessary to do a stage. Or to carry out here these SICK-LISTS, etc. in a separate field generally then also problems will not be at anybody.

3

Re: Synchronization of two .

I found in what a problem.
After a choice  in another  all fulfills correctly.

<option value = "22" selected = "selected"> the Sick-list </option>

Simply value does not put the necessary.
From here a question how to force it to display value correctly according to an option selected = "selected"?
, thanks for light, I will alter.

4

Re: Synchronization of two .

wrote:

vadipok;
Lay out here https://jsfiddle.net/for  a glitch

https://jsfiddle.net/9nwex5mb/8/

5

Re: Synchronization of two .

wrote:

vadipok;
Here
var employmentValue = $ ("#EmploymentID option:selected").text ().trim ();
if (employmentChange == 1 && (
employmentValue == ' the Sick-list ' ||
employmentValue == ' Business trip ' ||
employmentValue == ' Holiday ' ||
employmentValue == ' Holiday without the content ' ||
employmentValue == ' Social holiday ')) {

I do not understand, mean on value ()?
If so does not go.
There for each department ID and accordingly value (),  all it not to turn out.

6

Re: Synchronization of two .

wrote:


.trim ();
It generally superfluous if there was a necessity for your case it to use - means there is the full misunderstanding as as works, and not ability to use ide.
It not in insult, and to that that it is necessary to study much in this direction.

All is normal, I do not take offense at the facts.
Problem solved, it was necessary to use prop (' selected ', true);

$(' select [name = "ContractID"] option ').each (function () {
if ($ (this).attr (' selected ') === ' selected ') {
$(this).prop (' selected ', false);
}
})
$("#ContractID option").filter (function () {
return this.text.trim () == employmentValue;
}).prop (' selected ', true);