![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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. |
#3
| |||
| |||
|
|
On Jun 3, 11:45 am, sheldonlg <sheldonlg> wrote: 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? |
#4
| |||
| |||
|
|
after9 wrote: On Jun 3, 11:45 am, sheldonlg <sheldonlg> wrote: 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. |
#5
| |||
| |||
|
|
after9 wrote: On Jun 3, 11:45 am, sheldonlg <sheldonlg> wrote: 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 - |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
On Jun 3, 12:31 pm, sheldonlg <sheldonlg> wrote: after9 wrote: On Jun 3, 11:45 am, sheldonlg <sheldonlg> wrote: 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. |
#8
| |||
| |||
|
|
On Jun 3, 12:31 pm, sheldonlg <sheldonlg> wrote: after9 wrote: On Jun 3, 11:45 am, sheldonlg <sheldonlg> wrote: 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. |
#9
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |