Populate table at selection
Populate table at selection
am 22.04.2008 03:32:04 von freelance71
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. I've searched google and the examples require
java script. Is there a way to do this with only PHP. I had the impression
you could do anything with PHP. Infact there is a book titled 'How to do
every thing in PHP'!
--
When you argue with a fool, chances are he's doing the same
Re: Populate table at selection
am 22.04.2008 03:44:30 von Jerry Stuckle
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. I've searched google and the examples require
> java script. Is there a way to do this with only PHP. I had the impression
> you could do anything with PHP. Infact there is a book titled 'How to do
> every thing in PHP'!
> --
> When you argue with a fool, chances are he's doing the same
>
>
>
PHP is server side. A select box is client side. You need a client
side routine - i.e. javascript.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Populate table at selection
am 22.04.2008 08:08:06 von freelance71
"Jerry Stuckle" wrote in message
news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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. I've searched google and the examples require
>> java script. Is there a way to do this with only PHP. I had the
>> impression you could do anything with PHP. Infact there is a book titled
>> 'How to do every thing in PHP'!
>> --
>> When you argue with a fool, chances are he's doing the same
>
> PHP is server side. A select box is client side. You need a client side
> routine - i.e. javascript.
>
> --
Thanks.
Can a PHP script access/get the default value of a Combo box when the page
loads?
Re: Populate table at selection
am 22.04.2008 10:04:31 von Jeff North
On Tue, 22 Apr 2008 11:08:06 +0500, in comp.lang.php "freelance71"
wrote:
>|
>| "Jerry Stuckle" wrote in message
>| news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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. I've searched google and the examples require
>| >> java script. Is there a way to do this with only PHP. I had the
>| >> impression you could do anything with PHP. Infact there is a book titled
>| >> 'How to do every thing in PHP'!
>| >> --
>| >> When you argue with a fool, chances are he's doing the same
>| >
>| > PHP is server side. A select box is client side. You need a client side
>| > routine - i.e. javascript.
>| >
>| > --
>|
>| Thanks.
>| Can a PHP script access/get the default value of a Combo box when the page
>| loads?
If the default value is obtained from a database and php sets the
value then yes.
If the default value is within the HTML page then you will need to
parse the page (within php) to get the value. This needs to be done
before the page is sent to the browser.
Why don't you want to use javascript as what you've described is an
ideal candidate for AJAX.
-- ------------------------------------------------------------ -
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
-- ------------------------------------------------------------ -
Re: Populate table at selection
am 22.04.2008 13:23:35 von Jerry Stuckle
freelance71 wrote:
> "Jerry Stuckle" wrote in message
> news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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. I've searched google and the examples require
>>> java script. Is there a way to do this with only PHP. I had the
>>> impression you could do anything with PHP. Infact there is a book titled
>>> 'How to do every thing in PHP'!
>>> --
>>> When you argue with a fool, chances are he's doing the same
>> PHP is server side. A select box is client side. You need a client side
>> routine - i.e. javascript.
>>
>> --
>
> Thanks.
> Can a PHP script access/get the default value of a Combo box when the page
> loads?
>
>
>
If PHP is setting the value in the combobox, yes.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Populate table at selection
am 22.04.2008 19:11:31 von venti
On Apr 22, 7:23 am, Jerry Stuckle wrote:
> freelance71 wrote:
> > "Jerry Stuckle" wrote in message
> >news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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.
"
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
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;
}
Re: Populate table at selection
am 22.04.2008 19:42:16 von hellsop
On Tue, 22 Apr 2008 10:11:31 -0700 (PDT), venti wrote:
> On Apr 22, 7:23 am, Jerry Stuckle wrote:
>> freelance71 wrote:
>> > "Jerry Stuckle" wrote in message
>> >news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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.
> "
> 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
> 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;
> }
#3 looks a lot messier than #2. Never trust the client.
--
Mares eat oats, and does eat oats, and little lambs eat ivy,
A kid will eat ivy too, wouldn't you?
Re: Populate table at selection
am 22.04.2008 20:55:07 von venti
> #3 looks a lot messier than #2. Never trust the client.
Well, 3 requires more code up front, but it saves you having full
round trips with a page refresh. The payoff for Ajax is that the
headers remain the same, and only the div containing the table is
changed through the DOM.
As for trusting the client, of course, don't. This means, among other
things, client and (more important) server-side parsing for sql
injection. But ultimately I don't see any real difference in client
based attacks one way or the other.
Re: Populate table at selection
am 23.04.2008 05:46:49 von Chuck Anderson
Peter H. Coffin wrote:
> On Tue, 22 Apr 2008 10:11:31 -0700 (PDT), venti wrote:
>
>> On Apr 22, 7:23 am, Jerry Stuckle wrote:
>>
>>> freelance71 wrote:
>>>
>>>> "Jerry Stuckle" wrote in message
>>>> news:m5-dnZd-7K7Q35DVnZ2dnUVZ_uqdnZ2d@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.
>> "
>> 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
>> 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;
>> }
>>
>
> #3 looks a lot messier than #2. Never trust the client.
>
>
You can always make the Javascript fire from an event on a hyperlink
that would reload the entire page and accomplish the same thing for
those who do not have JS enabled.
--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************