Page 1 of 1

Fill In Multiple Selection Boxes From One Selection Box Sele

Posted: Thu Jul 19, 2007 8:21 am
by icesolid
I have a selection box at the top of my web site and then I have a bunch of rows printed out into a table from a MySQL database below that selection box.

Each one of these rows has a selection box in the first column.

I want the selection box that is at the top of all of these rows of data to fill the same value in as it if I select a value from it.

So if I select "Apples" from the selection box at the top of the table of data rows then all of the selection boxes in the table below would fill in with Apples.

Here is the code that the selection box at the top of the table of data rows has:

Code: Select all

<select name="assign_all" class="mediumInput"> 
<option value="">Select An Inspector</option> 
<?php 
$result1 = mysql_query("SELECT * FROM users WHERE account_type='Inspector' ORDER BY username ASC"); 

while($row1 = mysql_fetch_array($result1)) { 
?> 
  <option value="<?php echo $row1["user_code"]; ?>"><?php echo $row1["username"]; ?></option> 
<?php 
} 
?> 
</select>
Here is the code that each one of the selection boxes in the table has:

Code: Select all

<select name="inspector[<?php echo $row["id"]; ?>]" class="smallInput"> 
<option value="">Select An Inspector</option> 
<?php 
$result1 = mysql_query("SELECT * FROM users WHERE account_type='Inspector' ORDER BY username ASC"); 

while($row1 = mysql_fetch_array($result1)) { 
?> 
  <option value="<?php echo $row1["user_code"]; ?>"><?php echo $row1["username"]; ?></option> 
<?php 
} 
?> 
</select>
If an inspector is select in that top box I want all of the selection boxes below to fill in with that inspector.

Posted: Thu Jul 19, 2007 10:15 am
by pickle
Good luck with that - hope you figure it out :?

Posted: Thu Jul 19, 2007 1:12 pm
by icesolid
lol, thanks

Posted: Thu Jul 19, 2007 1:51 pm
by icesolid
I have no clue how else to explain it.

I want to have a selection box that is a master selection box (select all) that when a value is selected in it, it will fill in all of the selection boxes on the page with the same value it has in it.

Does that help?

feyd, where are you!?!?! lol

Posted: Thu Jul 19, 2007 2:32 pm
by pickle
Are there a set, finite number of "slave" selection boxes?

Posted: Thu Jul 19, 2007 3:04 pm
by TheMoose
This function looks at EVERY drop down box on the page, and if it's name attribute starts with the string "inspector", it will set the value to be whatever value you pass to the function (the actual value of the option, NOT the text that is displayed for that option).

Code: Select all

function SetValues(val) {
    var boxes = document.getElementsByTagName("select");
    for(var i=0;i<boxes.length;i++) {
        if(boxes[i].name.substr(0,9) == "inspector")
            for(var j=0;j<boxes[i].options.length;j++) {
                if(boxes[i].options[j].value == val) {
                    boxes[i].selectedIndex = j;
                    break;
                }
            }
        }
    }
}

Posted: Thu Jul 19, 2007 3:07 pm
by icesolid
Thanks for the help moose!

Posted: Thu Jul 19, 2007 3:16 pm
by icesolid
I have no errors, but when I select the main box the other boxes do not fill in?

Do I need to put some type of code in the main selection box to call the function?

Posted: Thu Jul 19, 2007 3:58 pm
by TheMoose
Yes, you need to set the onchange handler to fire that function, and pass it the value you want to select in the other boxes.

Posted: Fri Jul 20, 2007 8:43 am
by icesolid
I have tried this code here:

Code: Select all

onchange="SetValues();"
in my main selection box <select></select> tag.

No errors but the fields still do not fill in?

I have that javascript code you gave me underneith all of my form fields but inside of the </form> tag.