[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JS selection dependent

Posted on 2009-04-18
10
Medium Priority
?
448 Views
Last Modified: 2012-05-06
I've got <select> list and <select2> list.
Option values from <select> list are always the same and are always the same for <select2>.

The problem is that I need to: when on <select> list is choosen for ex. option 1 <select2> changes it's values. HOW TO DO IT WITHOUT CODE Looping? (not to put the same code many times)?

I would like to get solution in Jquery.
Thanks.
0
Comment
Question by:AndyPSV
  • 8
  • 2
10 Comments
 
LVL 3

Expert Comment

by:Chimeraza
ID: 24175160
A good one I use is:

http://www.ajaxray.com/blog/2007/11/08/jquery-controlled-dependent-or-cascading-select-list-2/

example of it here:
http://www.ajaxray.com/Examples/depend.html

I use other ones as well if this isn't what you're looking for.

Regards
Nick
0
 

Author Comment

by:AndyPSV
ID: 24176533
This script doesn't wants to work in my code ?? I don't know why, maybe updated jquery or sth.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:AndyPSV
ID: 24176577
My problem in this post is that that I need only to change on 1 option second field. Rest is without changes
AND I've got 250+ options; so what can I do to don't copy it all the time?
0
 

Author Comment

by:AndyPSV
ID: 24176641
Could someone provide me a working example of the code?
I've got a fog before my mind (without this: http://www.ajaxray.com/blog/2007/11/08/jquery-controlled-dependent-or-cascading-select-list-2/ or with modified to newest jquery version)
0
 
LVL 3

Accepted Solution

by:
Chimeraza earned 2000 total points
ID: 24176729
Ok because I also struggled trying to sort this out...  I have attached an exact working example...

Just unzip the files into a single directory (and rename them to .php) and run the runme.php file in your browser- and it will work.

You will see that by editing the cascade.php file you will be able to include all the items you wish to cascade inside that file and only call it from the javascript when you need it (save yourself having to type it out in every page).  

I have also included the required jquery file and selectbox.js file.

Let me know if you have any problems!

Regards
Nick
cascade.zip
0
 

Author Closing Comment

by:AndyPSV
ID: 31571753
THANKS!
0
 

Author Comment

by:AndyPSV
ID: 24177348
there is a problem with this script

-> select sth
-> now select <option> (blank)
-> select sth
-> -> now select <option> (blank)
IT STOPS WORK!
0
 

Author Comment

by:AndyPSV
ID: 24177368
ok, nvm; I've modified the script that it works - how to - when I select sth box appears; but when I return to the starting point it does not disappear - what to do ?
0
 

Author Comment

by:AndyPSV
ID: 24177379
Done it.

if ($pass_value == 'pass0') {
echo "{'0' : '-- Select Location --'}";
}


HTML.
<span id='select1Container'>
                        <select name='bc' id='selectId1' class=cc onchange='changeSelection( this )'><!--<% $bc[$k][id] %>-->
                              <option value='pass0'>&ndash;&nbsp;Select Category&nbsp;&ndash;</option>
                              <% foreach from = $bc key = k  item = v %><option value=<% if $bc[$k][id] == '1' %>pass1<% else %>pass2<%/if %><% if $GET[bc] == $bc[$k][id] %> selected<% /if %>><% $bc[$k][t] %></option><% /foreach %>
                        </select>
                  </span>
                  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question