SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with java script Options

    Hi,

    I realy need help from you guys on Java Script. I have 3 select boxes, and as soon as the option selected from either one, the other two select boxes will show the relative information to that selection.

    Exp.

    Like if I entered the car name the other two will have all the models from car and the year of the cars or if I select the model the car name and year should be selected.
    Aneal

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please help me out
    Aneal

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Cracow, Poland
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure how your script should work, but you can change selected item in your select box using

    Code:
    document.your_form_name.selectbox_name.selectedIndex = 5;
    attribute selectedIndex works on NS and IE and means which item is selected (first item has number 0)

    So if you want to change one select if another is changed you should write this

    Code:
    <script language="javascript">
    function mychange()
    {
       if (document.form.select1.selectedIndex == 1)
          document.form.select2.selectedIndex == 4;
    }
    </script>
    (numbers 1 and 4 are only for example)

    and in html you should add <select name=select1 onchange="mychange()">

    If you have good connection with Poland you can look at this http://www.mojeterminy.pl/s_nowy.php...81&t_ctg_id=40. It's one of my sites - in Polish language, but look at fields "Marka" and "Model", if you select "marka" then field model changes and you can select a model.


    bye

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply,

    It is helpful but I want to the values from the database for the select box. And there will be thousands of records. So I just want to write a query which will check the selected option and get me the data related to that partiqular option for the other select boxes.
    And I'm using PHPand Mysql with the java script.
    Thanks
    Aneal

  5. #5
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Cracow, Poland
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm... so it's not javascript problem but php.

    I made mojeterminy.pl (link in my previous post) in that way:
    I get car names and models from database. Using php generate javascript arrays (you can view source) and next, when user changes "select car name" I prepare new options to "select model" using new Option (great function! It's all in page source). It's quite easy, but you are right, that thousands of records are dangerous for browser (Now I have about 500 records x 3 arrays and everything works great).

    Other way is reload php script and generate new "select and options" in html source, but it's too slow for me
    Are you asking about this method?

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for your reply. I've tried to load up your site, but it was taking too much time to load. But yeah I do want it to work as PHP way. You are right it'll be slow that way but...
    Aneal

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like I didn't clear myself. Actually that's the good idea using the php generate javascript arrays and on changes "select car name" and options to "select model" using new Option, and I were not able to open your site to reffer the function which you have specified. I hope I made myself clear now.
    Aneal


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •