Discussion:
Notification of listbox selection change
Larry Martell
2013-12-09 20:40:16 UTC
Permalink
Is there any way in php to have a function be called when the value of
a listbox selection changes?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ashley Sheridan
2013-12-09 20:48:25 UTC
Permalink
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
PHP is executed on the server, that select list is on the client side.
To detect a change of the select list, you would have to use Javascript.

If there's something that absolutely has to be executed on the
server-side from this change (like an email, or database update) then
you could make an Ajax request to a PHP script. However, you've not said
what it is you want to do, only how to do what you think you should,
which are not the same things. If you explain in more detail what you're
trying to achieve, then we could offer better help.
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Larry Martell
2013-12-09 21:07:35 UTC
Permalink
On Mon, Dec 9, 2013 at 3:48 PM, Ashley Sheridan
Post by Ashley Sheridan
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
PHP is executed on the server, that select list is on the client side.
I know that. I thought perhaps there was some php construct that set
up some sort of Ajax request. I didn't think so,
Post by Ashley Sheridan
To detect a change of the select list, you would have to use Javascript.
If there's something that absolutely has to be executed on the
server-side from this change (like an email, or database update) then
you could make an Ajax request to a PHP script. However, you've not said
what it is you want to do, only how to do what you think you should,
which are not the same things. If you explain in more detail what you're
trying to achieve, then we could offer better help.
This is a mod to an existing app (that I didn't write)

Currently the user selects one item from a dropdown and clicks on a
submit button and they get a table of data based on their selection.
Via some javascript every 60 seconds the window is reloaded and the
table is updated (from the db which is changing).

What they want is a frame to the right of the table with a listbox
with all the choices (I have that coded.) When they select item(s)
from the listbox row(s) would get added to the table and when they
deselect items rows would be removed. They don't want to wait for the
next refresh nor have to click on a submit button.

Thanks.
-larry
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Richard S. Crawford
2013-12-09 20:48:15 UTC
Permalink
Not directly. JavaScript and AJAX would have to be involved, if I'm
understanding your question properly.
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Sláinte,
Richard S. Crawford (***@underpope.com) http://www.underpope.com
Twitter: http://twitter.com/underpope
Facebook: http://www.facebook.com/underpope
Google+: http://gplus.to/underpope
Stop the cat! Donate today! http://stayclassy.org/stonegoose
Larry Martell
2013-12-09 20:53:25 UTC
Permalink
That requires a separate request triggered by client-side scripting
(JavaScript).
That's what thought, just wanted to make sure. Thanks.
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tim Streater
2013-12-09 21:45:00 UTC
Permalink
Post by Larry Martell
What they want is a frame to the right of the table with a listbox
with all the choices (I have that coded.) When they select item(s)
from the listbox row(s) would get added to the table and when they
deselect items rows would be removed. They don't want to wait for the
next refresh nor have to click on a submit button.
You have to detect their actions on the javascript side, make an ajax request to the server, and have a PHP script respond with some data which you use to update the table.
--
Cheers -- Tim
Tedd Sperling
2013-12-14 14:00:15 UTC
Permalink
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
Larry:

Sure, take a look at this:

http://php1.net/a/zipcode-states/

Everything except the database is there -- you as you may.

Cheers,

tedd

_______________
tedd sperling
***@sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Larry Martell
2013-12-14 14:04:16 UTC
Permalink
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
Everything except the database is there -- you as you may.
Thanks much Tedd. I'll investigate this more next week. This may be
just what I need.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Larry Martell
2014-01-08 22:17:41 UTC
Permalink
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
Everything except the database is there -- you as you may.
Tedd-

Thanks very much for this. I just got around to trying it, and I
adapted it for my needs and it's basically working. The one issue I
have is that my request returns a complete new page and I want to
replace the existing page with that. The problem is that the request
originates from a frame and when I try and replace the page with the
response the new page get rendered within the frame. Do you know how
to replace the entire page with the response?

I've tried:

document.open();
document.write(response);
document.close();

and:

var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();

But I got the same undesirable results from both.

I realized this is not really a PHP question, but I wanted to continue
this thread here as others could benefit from it.

Thanks!
-larry
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph Michael Becker
2014-01-08 22:55:46 UTC
Permalink
Post by Larry Martell
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
The "javascript" *label* at the beginning of the onchange attribute's
value of the select elements is superfluous. The javascript pseudo
*protocol* is only valid for attributes that expect a URI -- but it
might better be avoided[1].
Post by Larry Martell
Thanks very much for this. I just got around to trying it, and I
adapted it for my needs and it's basically working. The one issue I
have is that my request returns a complete new page and I want to
replace the existing page with that. The problem is that the request
originates from a frame and when I try and replace the page with the
response the new page get rendered within the frame. Do you know how
to replace the entire page with the response?
To relace the current document with a new one, you can use the location
property of the window object[2]. In this case using a XMLHttpRequest
object is not necessary at all.
Post by Larry Martell
I realized this is not really a PHP question, but I wanted to
continue this thread here as others could benefit from it.
It might be better to separate concerns. :)

[1] <http://pointedears.de/scripts/faq/cljs/#javascriptURI>
[2] <https://developer.mozilla.org/en-US/docs/Web/API/Window.location>
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tedd Sperling
2014-01-09 18:15:09 UTC
Permalink
Larry:

You don't replace the entire page -- you fill-in the portion needed.

What you are missing here is DOM scripting.

The Ajax portion sends a GET request to a php script (get.php) that does all the db heavy work which in turn repopulates a "myspan" div, like so:

(index.php)

<div id="myspan"> <!-- start of myspan -->
<?php include("get.php"); ?>
</div> <!-- end of myspan -->

The get.php script has all the database stuff including the $_GET[] that brings in the state, city, and zip values.

Based upon what is provided, get.php script pulls the data from the db and populates the select controls with what is needed.

There is no refresh of the index page, but rather just an update of the "myspan" div via get.php.

HTH's

tedd

_______________
tedd sperling
Post by Larry Martell
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
Everything except the database is there -- you as you may.
Tedd-
Thanks very much for this. I just got around to trying it, and I
adapted it for my needs and it's basically working. The one issue I
have is that my request returns a complete new page and I want to
replace the existing page with that. The problem is that the request
originates from a frame and when I try and replace the page with the
response the new page get rendered within the frame. Do you know how
to replace the entire page with the response?
document.open();
document.write(response);
document.close();
var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();
But I got the same undesirable results from both.
I realized this is not really a PHP question, but I wanted to continue
this thread here as others could benefit from it.
Thanks!
-larry
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Larry Martell
2014-01-09 18:40:40 UTC
Permalink
Post by Tedd Sperling
You don't replace the entire page -- you fill-in the portion needed.
What you are missing here is DOM scripting.
(index.php)
<div id="myspan"> <!-- start of myspan -->
<?php include("get.php"); ?>
</div> <!-- end of myspan -->
The get.php script has all the database stuff including the $_GET[] that brings in the state, city, and zip values.
Based upon what is provided, get.php script pulls the data from the db and populates the select controls with what is needed.
There is no refresh of the index page, but rather just an update of the "myspan" div via get.php.
Tedd-

I understand how your code works. My application is slightly
different. My page looks like this:

<html>
<head>
<title>Main </title>
</head>
<frameset frameborder=1 border=1 rows="140,*">
<frame src="mainheader.php>
<frameset frameborder=1 border=1 cols='75%,25%'>
<frame src="main.php" name="main">
<frame src="selection.php" name="selection">
</frameset>
</frameset>
</html>
Post by Tedd Sperling
From within the selection frame I call your makeRequest function with
mainframes.php. I get back a complete new page. I got this to work by
doing this:

top.document.childNodes[0].innerHTML = response;

This works on FF, Chrome, and Safari, but on IE it fails with:

SCRIPT600: Could not set the innerHTML property. Invalid target
element for this operation. Still googling for a solution for that.
Post by Tedd Sperling
Post by Larry Martell
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
Everything except the database is there -- you as you may.
Tedd-
Thanks very much for this. I just got around to trying it, and I
adapted it for my needs and it's basically working. The one issue I
have is that my request returns a complete new page and I want to
replace the existing page with that. The problem is that the request
originates from a frame and when I try and replace the page with the
response the new page get rendered within the frame. Do you know how
to replace the entire page with the response?
document.open();
document.write(response);
document.close();
var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();
But I got the same undesirable results from both.
I realized this is not really a PHP question, but I wanted to continue
this thread here as others could benefit from it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tedd Sperling
2014-01-09 18:54:29 UTC
Permalink
Larry:

You are making this more complicated than it needs to be.

I simply have an index page that contains a div to hold the three selection controls (state/cit/zip).

I use another php script (get.php) to present/populate the selection controls AND gather the data needed.

The selection controls trigger the ajax routine like so:

<select name="state" onchange="javascript:get(this.parentNode);">

The ajax routine sends the value selected to the get.php script which in-turn repopulates the selection controls.

Repeat and rinse.

tedd

PS: Why use framesets?
_______________
tedd sperling
Post by Larry Martell
Post by Tedd Sperling
You don't replace the entire page -- you fill-in the portion needed.
What you are missing here is DOM scripting.
(index.php)
<div id="myspan"> <!-- start of myspan -->
<?php include("get.php"); ?>
</div> <!-- end of myspan -->
The get.php script has all the database stuff including the $_GET[] that brings in the state, city, and zip values.
Based upon what is provided, get.php script pulls the data from the db and populates the select controls with what is needed.
There is no refresh of the index page, but rather just an update of the "myspan" div via get.php.
Tedd-
I understand how your code works. My application is slightly
<html>
<head>
<title>Main </title>
</head>
<frameset frameborder=1 border=1 rows="140,*">
<frame src="mainheader.php>
<frameset frameborder=1 border=1 cols='75%,25%'>
<frame src="main.php" name="main">
<frame src="selection.php" name="selection">
</frameset>
</frameset>
</html>
From within the selection frame I call your makeRequest function with
mainframes.php. I get back a complete new page. I got this to work by
top.document.childNodes[0].innerHTML = response;
SCRIPT600: Could not set the innerHTML property. Invalid target
element for this operation. Still googling for a solution for that.
Post by Tedd Sperling
Post by Larry Martell
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
Everything except the database is there -- you as you may.
Tedd-
Thanks very much for this. I just got around to trying it, and I
adapted it for my needs and it's basically working. The one issue I
have is that my request returns a complete new page and I want to
replace the existing page with that. The problem is that the request
originates from a frame and when I try and replace the page with the
response the new page get rendered within the frame. Do you know how
to replace the entire page with the response?
document.open();
document.write(response);
document.close();
var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();
But I got the same undesirable results from both.
I realized this is not really a PHP question, but I wanted to continue
this thread here as others could benefit from it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Larry Martell
2014-01-09 19:14:25 UTC
Permalink
Post by Tedd Sperling
You are making this more complicated than it needs to be.
I simply have an index page that contains a div to hold the three selection controls (state/cit/zip).
I use another php script (get.php) to present/populate the selection controls AND gather the data needed.
<select name="state" onchange="javascript:get(this.parentNode);">
The ajax routine sends the value selected to the get.php script which in-turn repopulates the selection controls.
Repeat and rinse.
tedd
PS: Why use framesets?
Like I said, I totally understand how your code works. This is not a
new app I am developing from scratch. It's a big existing app that was
written a long time ago. Currently when the user makes selections they
have to click on a submit button. I was asked to make it so that their
selections take effect immediately and to get rid of the submit
button. The easiest thing for me to do was to call the same php code
that get called when the submit button is clicked. I have it working,
I just need to find a workaround for IE. Apparently innerHTML is
read-only in IE. I've read that using jQuery gets around this. But
jQuery is not installed on my client's sites.
Post by Tedd Sperling
Post by Larry Martell
Post by Tedd Sperling
You don't replace the entire page -- you fill-in the portion needed.
What you are missing here is DOM scripting.
(index.php)
<div id="myspan"> <!-- start of myspan -->
<?php include("get.php"); ?>
</div> <!-- end of myspan -->
The get.php script has all the database stuff including the $_GET[] that brings in the state, city, and zip values.
Based upon what is provided, get.php script pulls the data from the db and populates the select controls with what is needed.
There is no refresh of the index page, but rather just an update of the "myspan" div via get.php.
Tedd-
I understand how your code works. My application is slightly
<html>
<head>
<title>Main </title>
</head>
<frameset frameborder=1 border=1 rows="140,*">
<frame src="mainheader.php>
<frameset frameborder=1 border=1 cols='75%,25%'>
<frame src="main.php" name="main">
<frame src="selection.php" name="selection">
</frameset>
</frameset>
</html>
From within the selection frame I call your makeRequest function with
mainframes.php. I get back a complete new page. I got this to work by
top.document.childNodes[0].innerHTML = response;
SCRIPT600: Could not set the innerHTML property. Invalid target
element for this operation. Still googling for a solution for that.
Post by Tedd Sperling
Post by Larry Martell
Post by Tedd Sperling
Post by Larry Martell
Is there any way in php to have a function be called when the value of
a listbox selection changes?
http://php1.net/a/zipcode-states/
Everything except the database is there -- you as you may.
Tedd-
Thanks very much for this. I just got around to trying it, and I
adapted it for my needs and it's basically working. The one issue I
have is that my request returns a complete new page and I want to
replace the existing page with that. The problem is that the request
originates from a frame and when I try and replace the page with the
response the new page get rendered within the frame. Do you know how
to replace the entire page with the response?
document.open();
document.write(response);
document.close();
var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();
But I got the same undesirable results from both.
I realized this is not really a PHP question, but I wanted to continue
this thread here as others could benefit from it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph Michael Becker
2014-01-09 19:29:03 UTC
Permalink
Post by Larry Martell
Like I said, I totally understand how your code works. This is not a
new app I am developing from scratch. It's a big existing app that was
written a long time ago. Currently when the user makes selections they
have to click on a submit button. I was asked to make it so that their
selections take effect immediately and to get rid of the submit
button. The easiest thing for me to do was to call the same php code
that get called when the submit button is clicked. I have it working,
I just need to find a workaround for IE. Apparently innerHTML is
read-only in IE. I've read that using jQuery gets around this. But
jQuery is not installed on my client's sites.
You do not want to replace the innerHTML of the HTML element -- instead
simply relocate (google for window.location or see my last reply) to the
desired "page" (and forget about the Ajax stuff for this scenario).
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
2014-01-09 19:48:02 UTC
Permalink
Post by Larry Martell
Like I said, I totally understand how your code works. This is not a
new app I am developing from scratch. It's a big existing app that was
written a long time ago. Currently when the user makes selections they
have to click on a submit button. I was asked to make it so that their
selections take effect immediately and to get rid of the submit
button. The easiest thing for me to do was to call the same php code
that get called when the submit button is clicked. I have it working,
I just need to find a workaround for IE. Apparently innerHTML is
read-only in IE. I've read that using jQuery gets around this. But
jQuery is not installed on my client's sites.
Post by Larry Martell
I understand how your code works. My application is slightly
<html>
<head>
<title>Main </title>
</head>
<frameset frameborder=1 border=1 rows="140,*">
<frame src="mainheader.php>
<frameset frameborder=1 border=1 cols='75%,25%'>
<frame src="main.php" name="main">
<frame src="selection.php" name="selection">
</frameset>
</frameset>
</html>
Set a target on your form and add onchange="this.form.submit()" to your select
element.

http://www.w3.org/TR/html401/present/frames.html#h-16.3

Checkout this:
http://www.cmsws.com/examples/php/testscripts/***@gmail.com/
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Larry Martell
2014-01-09 19:56:22 UTC
Permalink
Post by Jim Lucas
Post by Larry Martell
Like I said, I totally understand how your code works. This is not a
new app I am developing from scratch. It's a big existing app that was
written a long time ago. Currently when the user makes selections they
have to click on a submit button. I was asked to make it so that their
selections take effect immediately and to get rid of the submit
button. The easiest thing for me to do was to call the same php code
that get called when the submit button is clicked. I have it working,
I just need to find a workaround for IE. Apparently innerHTML is
read-only in IE. I've read that using jQuery gets around this. But
jQuery is not installed on my client's sites.
Post by Larry Martell
I understand how your code works. My application is slightly
<html>
<head>
<title>Main </title>
</head>
<frameset frameborder=1 border=1 rows="140,*">
<frame src="mainheader.php>
<frameset frameborder=1 border=1 cols='75%,25%'>
<frame src="main.php" name="main">
<frame src="selection.php" name="selection">
</frameset>
</frameset>
</html>
Set a target on your form and add onchange="this.form.submit()" to your
select element.
http://www.w3.org/TR/html401/present/frames.html#h-16.3
OMG! That is ridiculously simple! Works perfectly. Thank you very much!!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...