473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Question with AJAX

I am still improving my AJAX and I ran into something that I'm not sure
how to do.

I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. The display depends upon what is
currently selected in the dropdown. This is readily done via AJAX which
is activated with an onchange in the dropdown list. The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.

So far OK. What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. I don't want to repeat code in two places.

One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. I would just use different values for the
selected item. It would be on the display page as a require_once before
I do any html display.

My question is whether there is some better way.
Jun 27 '08 #1
8 1026
On Jun 3, 11:45*am, sheldonlg <sheldonlgwrote:
I am still improving my AJAX and I ran into something that I'm not sure
how to do.

I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. *The display depends upon what is
currently selected in the dropdown. *This is readily done via AJAX which
is activated with an onchange in the dropdown list. *The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.

So far OK. *What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. *I don't want to repeat code in two places.

One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. *I would just use different values for the
selected item. *It would be on the display page as a require_once before
I do any html display.

My question is whether there is some better way.
Is the dropdown list dynamic or static?

If it is static and you are using a GET method (which seems logical, I
don't believe you are manipulating any data, merely retrieving it)
then why not just initiate the page using your script passing it the
desired value?

Jun 27 '08 #2
after9 wrote:
On Jun 3, 11:45 am, sheldonlg <sheldonlgwrote:
>I am still improving my AJAX and I ran into something that I'm not sure
how to do.

I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. The display depends upon what is
currently selected in the dropdown. This is readily done via AJAX which
is activated with an onchange in the dropdown list. The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.

So far OK. What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. I don't want to repeat code in two places.

One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. I would just use different values for the
selected item. It would be on the display page as a require_once before
I do any html display.

My question is whether there is some better way.

Is the dropdown list dynamic or static?

If it is static and you are using a GET method (which seems logical, I
don't believe you are manipulating any data, merely retrieving it)
then why not just initiate the page using your script passing it the
desired value?
It is dynamic. Once in the page, a list is build from the category
passed in. It is that list that is then used to display what is in the
bottom of the page. The first llist is a db call. The second list is
also a db call using the value from the first list. Coming into the
page, we have no idea as to what the id will be for the first member on
the first list.

The more I think of it, the more the require_once of the building code
looks like the way to go. There is no duplication of code (one include
file) and it is just exercised in two different places.
Jun 27 '08 #3
On Jun 3, 12:31*pm, sheldonlg <sheldonlgwrote:
after9 wrote:
On Jun 3, 11:45 am, sheldonlg <sheldonlgwrote:
I am still improving my AJAX and I ran into something that I'm not sure
how to do.
I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. *The display depends upon what is
currently selected in the dropdown. *This is readily done via AJAX which
is activated with an onchange in the dropdown list. *The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.
So far OK. *What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. *I don't want to repeat code in two places.
One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. *I would just use different values for the
selected item. *It would be on the display page as a require_once before
I do any html display.
My question is whether there is some better way.
Is the dropdown list dynamic or static?
If it is static and you are using a GET method (which seems logical, I
don't *believe you are manipulating any data, merely retrieving it)
then why not just initiate the page using your script passing it the
desired value?

It is dynamic. *Once in the page, a list is build from the category
passed in. *It is that list that is then used to display what is in the
bottom of the page. *The first llist is a db call. *The second list is
also a db call using the value from the first list. *Coming into the
page, we have no idea as to what the id will be for the first member on
the first list.

The more I think of it, the more the require_once of the building code
looks like the way to go. *There is no duplication of code (one include
file) and it is just exercised in two different places.
So let me get the workflow straight.

1. A user selects a category.
2. This category is passed to the display page.
3. On display page, a dropdown list is populated via a database query
of category that was passed.
4. On a dropdown change event a request is passed to a php script.
5. The php script returns database information to display page.

When #3 happens you want the display section to automatically load the
information of the first dropdown option of the category.

One solution involves the steps prior to #3. Along with passing the
category, why not pass along the first item in category's database?
Then you could have a GET request of something like display.php?
category=foo&first=bar. In the display page you could check if
$_GET["first"] is set and then handle it appropriately.
Jun 27 '08 #4
On Jun 3, 12:31*pm, sheldonlg <sheldonlgwrote:
after9 wrote:
On Jun 3, 11:45 am, sheldonlg <sheldonlgwrote:
I am still improving my AJAX and I ran into something that I'm not sure
how to do.
I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. *The display depends upon what is
currently selected in the dropdown. *This is readily done via AJAX which
is activated with an onchange in the dropdown list. *The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.
So far OK. *What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. *I don't want to repeat code in two places.
One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. *I would just use different values for the
selected item. *It would be on the display page as a require_once before
I do any html display.
My question is whether there is some better way.
Is the dropdown list dynamic or static?
If it is static and you are using a GET method (which seems logical, I
don't *believe you are manipulating any data, merely retrieving it)
then why not just initiate the page using your script passing it the
desired value?

It is dynamic. *Once in the page, a list is build from the category
passed in. *It is that list that is then used to display what is in the
bottom of the page. *The first llist is a db call. *The second list is
also a db call using the value from the first list. *Coming into the
page, we have no idea as to what the id will be for the first member on
the first list.

The more I think of it, the more the require_once of the building code
looks like the way to go. *There is no duplication of code (one include
file) and it is just exercised in two different places.- Hide quoted text -

- Show quoted text -

In the code that populates your dropdown, after populating the
dropdown simply set the selectedIndex of it to 0 and then call the
function that is called by the onchange handler, or you can even call
onchange() of the element.

function loadMyDropDown() {
var select = document.getElementById("categories");
//...populate the dropdown...
if (select.options.length 0) {
select.selectedIndex = 0;
select.onchange();
}
}

HTH.
Jun 27 '08 #5
the bad thing about toms method is, if javascript is deactivated the
user will see nothing. I favoured your solution when I had the problem
first, for me it worked well. One tip about it: i would ad an ?ajax to
all ajax calls, e.g. includes/ajax3.php?ajax
by using if(isset($_GET['ajax'])) you can check if your file is called
by ajax or if it is included. So if you have differences in some
pathes or anything else you can avoid problems with this method
Jun 27 '08 #6
after9 wrote:
On Jun 3, 12:31 pm, sheldonlg <sheldonlgwrote:
>after9 wrote:
>>On Jun 3, 11:45 am, sheldonlg <sheldonlgwrote:
I am still improving my AJAX and I ran into something that I'm not sure
how to do.
I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. The display depends upon what is
currently selected in the dropdown. This is readily done via AJAX which
is activated with an onchange in the dropdown list. The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.
So far OK. What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. I don't want to repeat code in two places.
One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. I would just use different values for the
selected item. It would be on the display page as a require_once before
I do any html display.
My question is whether there is some better way.
Is the dropdown list dynamic or static?
If it is static and you are using a GET method (which seems logical, I
don't believe you are manipulating any data, merely retrieving it)
then why not just initiate the page using your script passing it the
desired value?
It is dynamic. Once in the page, a list is build from the category
passed in. It is that list that is then used to display what is in the
bottom of the page. The first llist is a db call. The second list is
also a db call using the value from the first list. Coming into the
page, we have no idea as to what the id will be for the first member on
the first list.

The more I think of it, the more the require_once of the building code
looks like the way to go. There is no duplication of code (one include
file) and it is just exercised in two different places.

So let me get the workflow straight.

1. A user selects a category.
2. This category is passed to the display page.
3. On display page, a dropdown list is populated via a database query
of category that was passed.
4. On a dropdown change event a request is passed to a php script.
5. The php script returns database information to display page.

When #3 happens you want the display section to automatically load the
information of the first dropdown option of the category.

One solution involves the steps prior to #3. Along with passing the
category, why not pass along the first item in category's database?
Then you could have a GET request of something like display.php?
category=foo&first=bar. In the display page you could check if
$_GET["first"] is set and then handle it appropriately.
....because I don't KNOW the first item before getting to the page and
running the first db query to populate the list of items. The items are
identified by an ID which is obtained from the db based up the category ID.
Jun 27 '08 #7
Tom Cole wrote:
On Jun 3, 12:31 pm, sheldonlg <sheldonlgwrote:
>after9 wrote:
>>On Jun 3, 11:45 am, sheldonlg <sheldonlgwrote:
I am still improving my AJAX and I ran into something that I'm not sure
how to do.
I will have a page called where I will have a dropdown list at the top
and a large display at the bottom. The display depends upon what is
currently selected in the dropdown. This is readily done via AJAX which
is activated with an onchange in the dropdown list. The contents of the
bottom half of the page are created in the php script which is sent back
to the response handler which changed the bottom part via an innerHTML.
So far OK. What I would also like to happen is that when the page is
called initially, that the bottom half shows for the first entry of the
dropdown list. I don't want to repeat code in two places.
One solution I have is to have the entire selection and bottom building
part be an include file that I put into both my AJAX server php script
and into this display page. I would just use different values for the
selected item. It would be on the display page as a require_once before
I do any html display.
My question is whether there is some better way.
Is the dropdown list dynamic or static?
If it is static and you are using a GET method (which seems logical, I
don't believe you are manipulating any data, merely retrieving it)
then why not just initiate the page using your script passing it the
desired value?
It is dynamic. Once in the page, a list is build from the category
passed in. It is that list that is then used to display what is in the
bottom of the page. The first llist is a db call. The second list is
also a db call using the value from the first list. Coming into the
page, we have no idea as to what the id will be for the first member on
the first list.

The more I think of it, the more the require_once of the building code
looks like the way to go. There is no duplication of code (one include
file) and it is just exercised in two different places.- Hide quoted text -

- Show quoted text -


In the code that populates your dropdown, after populating the
dropdown simply set the selectedIndex of it to 0 and then call the
function that is called by the onchange handler, or you can even call
onchange() of the element.
That is essentially to the way I now handle it. I took the bulk of the
called function and put it in a separate php file that is included in
the called function. What is not in that include file is the grabbing
of the category ID. The category ID is obtained from a $_GET from the
AJAX call. In the display page I also include that included file, but
use as the category the first entry from the dropdown list. That way I
have no duplication of code.
>
function loadMyDropDown() {
var select = document.getElementById("categories");
//...populate the dropdown...
if (select.options.length 0) {
select.selectedIndex = 0;
select.onchange();
}
}

HTH.
Jun 27 '08 #8
ma*********@web.de wrote:
the bad thing about toms method is, if javascript is deactivated the
user will see nothing. I favoured your solution when I had the problem
first, for me it worked well. One tip about it: i would ad an ?ajax to
all ajax calls, e.g. includes/ajax3.php?ajax
by using if(isset($_GET['ajax'])) you can check if your file is called
by ajax or if it is included. So if you have differences in some
pathes or anything else you can avoid problems with this method
Great suggestion.
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: HockeyFan | last post by:
I'd like to have an AJAX textbox that after the user fills in, will auto-fill another textbox on the page without having a postback occur. It doesn't have to do any filtering or any other thing...
4
by: Peter | last post by:
I have a button on my ASP.NET 2.0 web page labelled "Copy to Clipboard" which must use server side code to format some data in a specific manner and then copy it to the client clipboard so it can...
2
by: Cirene | last post by:
3 quick questions... 1. Are the controls in the AJAX Futures download "beta" or the release and stable version? 2. Also, where is the best way to learn how to implement these? (Other than by...
6
by: Jonathan Wood | last post by:
Greetings, I'd like to implement some AJAX features on an existing ASP.NET site. I have one example of doing this but, otherwise, don't know much about it. I have one question, though, about...
2
by: Ronald Raygun | last post by:
I have a form, which contains a textfield for a user to enter their username. I want to provide a button that allows the user to check to see whether that username has already been taken up by...
8
by: sheldonlg | last post by:
I am still improving my AJAX and I ran into something that I'm not sure how to do. I will have a page called where I will have a dropdown list at the top and a large display at the bottom. The...
4
by: slebetman | last post by:
On Jun 5, 9:36 pm, sheldonlg <sheldonlgwrote: You can of course use closure to pass the required parameter: var hideIt; // the variable you wish to pass ajax.onreadystatechange = function () {...
22
by: sheldonlg | last post by:
I am looking for a clean solution to a problem that I solved in, what I call, a "dirty" way. Here is what I want to do. I have a dropdown list. Clicking on an item in the dropdown list invokes...
25
by: Mark | last post by:
so, i'm making a website. let's say i have header.php, footer.php and content.php. now in index.php I simply want to include the 3 pages. easy enough to do. but let's say the user navigates to...
1
by: luigi.corrias | last post by:
Hello everybody, this is a very difficult question… imagine 2 webform asp.net A and B B is an iframe inside A..
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.