On Apr 22, 7:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
freelance71 wrote:
"Jerry Stuckle" <jstuck...@attglobal.netwrote in message
news:m5******************************@comcast.com. ..
freelance71 wrote:
I have a combo box (select) and when the user selects a value I want to
populate an HTML table from DB depending on the value selected. Whats the
easiest way to achieve it.
You can do it all with PHP if you'd like, although it might get
messy .
You've got 3 ways to go:
1) The Wrong Way.
Bake everything into the file using php. This means creating the
select form with php, and also dynamically creating javascript with
php. Because you already know the only possibly options the user might
select, you just load the different table data though php/mysql and
shove them into javascript variables (within php. i.e. <?php echo
"<script type=\text/javascript\"";.....) You will be heading down the
rabbit hole this way.
2) The Old Way:
Create the form with HTML. Set the form action to a PHP page (It can
even be the same page that displays the form)
The form sends a GET request to the PHP Page, you take the value the
user has chosen with $userchoice=$_GET['userchoice']; Work your magic
with mysql, and create a table with the data and display the data with
a inline php variable.
3) The Right Way:
Use Ajax:
Create a div specifically for the table
Set one of the SELECT events to a custom javascript handler.
something like <inputtype = "select" id="myselect"
onmouseup="javascript
:myHandler(this.form);"
then u make a javascript function
function myHandler(form)
{
myselect = form.select.value;
}
Then you use your favorite Ajax framework to send the value to the
server (via ajax) you will need to write a custom callback handler for
the data that comes back from php.
function callBackAjaxHandler(response)
{
document.getElementById('mytablediv').innerHTML = response;
}