Results 1 to 2 of 2

Thread: PHP Selects and output - dynamic update?

  1. #1
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default PHP Selects and output - dynamic update?

    Hi guys

    I have two select boxes of which a user will select an item from select box 1 and then select box 2 will refresh with options that only match the first selected select box.

    Second is that I need to have a hidden form output to dynamically change also based on the selection of select box 1.

    How do I do this within php, or do I need to use javascript?

    I was trying to use strpos but while that works it does not dynamically change the select boxes...

    PHP Code:
    <?php
            $size 
    'asize';    
            
    $findme   'asizestring';
        
    $sel strpos($size$findme);
        
        if (
    $sel === false) {
        echo 
    '<option value="option1Choice1" selected>Option1 choice1</option>
        <option value="option1choice2">option1choice2</option>'
    ;
    } else {
        echo 
    '<option value="option2choice1" selected>option2 Choice1</option>
        <option value="option2choice2">option2 choice 2'
    ;
    }
         
    ?>
    help please

    Cheers
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

  2. #2
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    i have somewhat the same thing in a page I have. my select lists are for states and counties.

    the cid var below is a hidden value in the form. then based on the state id passed in the url i then load the counties list.

    Code:
    <SCRIPT language=JavaScript>
    function reload(form)
    {
    var val=form.state_id.options[form.state_id.options.selectedIndex].value;
    var cid=form.clubid.value;
    self.location='yoururl&clubid=' + cid + '&state_id=' + val ;
    }
    </script>
    
    then in the html
    echo "<select name='state_id' onchange=\"reload(this.form)\"><option value=''>Select a State</option>";
    
    this is the county select based on the state_id passed
                      if(isset($state_id) and strlen($state_id) > 0){
                          $cquery=mysql_query("SELECT * FROM ".$prefix."_counties where state_id=$state_id order by name"); 
                      }
    
    careful as your submit button cant be named "submit"

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
  •