Проблем с Jquery и проверка на селект

C++ JAVA
Post Reply
Knoppix_
Турист
Турист
Posts: 322
Joined: Mon Aug 24, 2009 11:55 am

Проблем с Jquery и проверка на селект

Post by Knoppix_ » Wed Feb 17, 2016 6:22 am

Това ми кода за Jquery

Code: Select all

<script>
            $&#40;document&#41;.ready&#40;function &#40;&#41; &#123;
                var secondArray = &#91;&#93;;
                $&#40;'#userLang2 option'&#41;.each&#40;function &#40;&#41; &#123;
                    secondArray.push&#40;&#123;key&#58; $&#40;this&#41;.val&#40;&#41;, value&#58; $&#40;this&#41;.text&#40;&#41;&#125;&#41;;
                &#125;&#41;;
                $&#40;'#userLang1'&#41;.change&#40;function &#40;&#41; &#123;
                    var dynamicVal = $&#40;this&#41;.val&#40;&#41;;
                   
                    $&#40;"#userLang2"&#41;.find&#40;'option'&#41;.remove&#40;&#41;;
                    $.each&#40;secondArray, function &#40;i, v&#41; &#123;
                        if&#40;v.key != dynamicVal&#41;&#123;
                            $&#40;'#userLang2'&#41;.append&#40;$&#40;'<option>', &#123;value&#58; v.key&#125;&#41;.text&#40;v.value&#41;&#41;;
                        &#125;
                    &#125;&#41;;
                &#125;&#41;;
            &#125;&#41;;
			$&#40;document&#41;.ready&#40;function &#40;&#41; &#123;
                var thirdArray = &#91;&#93;;
                $&#40;'#userLang3 option'&#41;.each&#40;function &#40;&#41; &#123;
                    thirdArray.push&#40;&#123;key&#58; $&#40;this&#41;.val&#40;&#41;, value&#58; $&#40;this&#41;.text&#40;&#41;&#125;&#41;;
                &#125;&#41;;
                $&#40;'#userLang1 && #userLang2'&#41;.change&#40;function &#40;&#41; &#123;
                    var dynamicVal = $&#40;this&#41;.val&#40;&#41;;
                   
                    $&#40;"#userLang3"&#41;.find&#40;'option'&#41;.remove&#40;&#41;;
                    $.each&#40;thirdArray, function &#40;i, v&#41; &#123;
                        if&#40;v.key != dynamicVal&#41;&#123;
                            $&#40;'#userLang3'&#41;.append&#40;$&#40;'<option>', &#123;value&#58; v.key&#125;&#41;.text&#40;v.value&#41;&#41;;
                        &#125;
                    &#125;&#41;;
                &#125;&#41;;
            &#125;&#41;;
 </script>
Идеята е следната имам три селект-а при избор на стойност от първият да се премахва от вторият, при избор на стойност от вторият да се вземат стойностите от първият и от вторият и да се премахват в третия

Knoppix_
Турист
Турист
Posts: 322
Joined: Mon Aug 24, 2009 11:55 am

Post by Knoppix_ » Wed Feb 17, 2016 6:51 am

Ето така трябва да изглежда Jquery-to за да се получи

Code: Select all

$&#40;document&#41;.ready&#40;function&#40;&#41;&#123;
$&#40;'select'&#41;.on&#40;'change', function&#40;event &#41; &#123;
   var prevValue = $&#40;this&#41;.data&#40;'previous'&#41;;
$&#40;'select'&#41;.not&#40;this&#41;.find&#40;'option&#91;value="'+prevValue+'"&#93;'&#41;.show&#40;&#41;;    
   var value = $&#40;this&#41;.val&#40;&#41;;
  $&#40;this&#41;.data&#40;'previous',value&#41;; $&#40;'select'&#41;.not&#40;this&#41;.find&#40;'option&#91;value="'+value+'"&#93;'&#41;.hide&#40;&#41;;
&#125;&#41;;
&#125;&#41;;

User avatar
mitkosoft
Нов
Нов
Posts: 21
Joined: Mon Feb 08, 2016 2:27 pm

Post by mitkosoft » Wed Feb 17, 2016 8:04 am

T.e. в крайна сметка има ли проблем или не? :)

User avatar
SVTerziev
Нов
Нов
Posts: 158
Joined: Fri Jul 13, 2012 12:32 am
Answers: 34

Post by SVTerziev » Wed Feb 17, 2016 10:34 am


Post Reply