sub select box

Discussion in 'PHP' started by roice, Mar 2, 2011.

  1. #1
    Hello,
    I have DB of category (id, name) and DB of sub_category (id, category_id, name)
    I want to do select box for sub_category that will be changed according to the "category" box.
    I mean - if I'm choosing the second category I will see different options on the sub category box.

    Can you please help me with that?
     
    roice, Mar 2, 2011 IP
  2. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What kind of help do you need, it is fairly straightforward. When the user changes the selection in the first select box invoke a javascript call to populate the second select box using AJAX.
     
    MartinPrestovic, Mar 2, 2011 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    roice, Mar 2, 2011 IP
  4. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes I can see the select boxes and yes I see that they are working in FF. I don't use IE so can't run a test on that, but as you said it's not working in IE6 for you I did a little digging based on that information.

    Looking over the source code of your web site, this isn't a PHP problem but rather a problem in jQuery. This isn't really my area of expertise as I tend to avoid libraries and custom develop stuff, but I did some searches for you and this is what I found.

    This guy, used the following code directly above his problem code and this got it working:

    
    if (!XMLHttpRequest) {
          window.XMLHttpRequest = function() {
          return new ActiveXObject('Microsoft.XMLHTTP');
          }
      }
    
    Code (markup):
    This next guy also had the same problem, code not working in IE6 but in this case he is using the jQuery library. As I said, I don't use jQuery, but you might be able to read through that page and spot something which will get your code working.

    HTH
     
    MartinPrestovic, Mar 2, 2011 IP
  5. Mike Griffiths

    Mike Griffiths Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You'll need to invoke a JavaScript call to a script that contains details for the second select box. Some pseudo code for this below:
    User selects from select1
    select1 value passed via JS to subselect.php
    subselect.php queries database for that value, and returns all options in <option value="">sub select value</option> format
    Your JS on the original page populates the select using innerHTML
    Code (markup):
    You can do this with just a couple of functions using a JS framework like JQuery
     
    Mike Griffiths, Mar 4, 2011 IP
  6. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    you may want to simply find a good tutorial to get the multibrowser portion working and then modify it to work with your specifics.
     
    srisen2, Mar 4, 2011 IP
  7. Mike Griffiths

    Mike Griffiths Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Just use jQuery, then you don't have to worry about cross-browser support.
     
    Mike Griffiths, Mar 4, 2011 IP
  8. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Mike, perhaps reading his second response and looking at the link he posted which shows he already has the two select boxes in place, using jQuery and they are working.... his problem is that they are not working in IE6.
     
    MartinPrestovic, Mar 4, 2011 IP
  9. Mike Griffiths

    Mike Griffiths Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Missed that, apologies.

    Try putting the script within <head>.
     
    Mike Griffiths, Mar 5, 2011 IP