Entry
How to add a second listbox (eg author of a book, db content) to a form when first author is chosen?
May 2nd, 2007 06:19
lorenzo campanis, Michel Kriens, Onno Benschop,
Truly, you wouldnt need php to do that but Javascript... You can try
this by printing out a new select from scratch, but the easiest way
would be to have the selects already printed inside divs and show them
depending on the selection your 1st input has... You can hide the divs
using css
display:none and show them with display:block
using a CSS class for this, is better and you can have the following
javascript to change the classname when an option is selected from the
1st select.
Here's the code:
<select name="select" onchange="showHide(this)">
<option value="">Select an Option</option>
<option value="authors">Authors</option>
<option value="publishers">Publishers</option>
</select>
<script>
function showHide(select)
{
//get the select's value
var val = select.value;
//depending on the 1st slects value we show what we want
//however we have to hide the currently showing DIV
//this is achieved by looping through the elements
//so get the elements we need to hide here by making their
className='hide'
.....
//once achieved show your DIV
if(val == 'authors')
document.getElementById('authorDiv').className = 'show';
}
</script>
Lorenzo ;)