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 an AJAX call that gets data which populates
the entire lower part of my screen. It does this with an innerHTML for
the div tag that holds all of this. This works fine.
I also have an "Edit" button that I want to show next to dropdown list,
but only if certain conditions are met for the item selected. I don't
know those conditions until after the AJAX call (which has the db query).
The way I tried to implement this was to create a hidden field in the
area written from the AJAX call, with its value set to 0 or 1 during the
AJAX call. On return, right after doing the innerHTML, in the same
javascript function, I interrogate that hidden field and set the display
attribute of the span encompassing the "Edit" button to either '' or none.
In the initial composition of the page, I selected the first item in the
dropdown list and called the inside code to generate the stuff inside
the div so that my page is initially filled.
Here is the problem. I have two items in the dropdown list. The first
one generates a 0 for the hidden field. The second generates a 1. (I
have put print statements into the code and those values are calculated
properly.) However, the edit button never shows. So, when the second
one is being displayed (where it should be 1 and show the edit button),
I did a view source. What appeared was the entire display for the first
one along with a value of 0.
So, here is my question. How can I transfer information within the AJAX
call, other that the entire bottom display which works fine, so that I
can do the post-processing to either hide or show the edit button.
I thought it might be an "imprinting " of this hidden variable, but it is
not. I moved that piece of code out of the inital page build and only
appearing in the AJAX call. Of course, the hidden variable didn't show
up at all since the view source only showed the results for the first
one which did not use the AJAX call.
I implemented a rather "dirty" way and it worked. I prepend the entire
return from AJAX with either a 0 or a 1. On the return, I separate the
two, and then innerHTML with the string start at position 1 and use the
first value for show/hide. However, I was wondering if there is a
better, cleaner, way.
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 an AJAX call that gets data which populates
the entire lower part of my screen. It does this with an innerHTML for
the div tag that holds all of this. This works fine.
I also have an "Edit" button that I want to show next to dropdown list,
but only if certain conditions are met for the item selected. I don't
know those conditions until after the AJAX call (which has the db query).
The way I tried to implement this was to create a hidden field in the
area written from the AJAX call, with its value set to 0 or 1 during the
AJAX call. On return, right after doing the innerHTML, in the same
javascript function, I interrogate that hidden field and set the display
attribute of the span encompassing the "Edit" button to either '' or none.
In the initial composition of the page, I selected the first item in the
dropdown list and called the inside code to generate the stuff inside
the div so that my page is initially filled.
Here is the problem. I have two items in the dropdown list. The first
one generates a 0 for the hidden field. The second generates a 1. (I
have put print statements into the code and those values are calculated
properly.) However, the edit button never shows. So, when the second
one is being displayed (where it should be 1 and show the edit button),
I did a view source. What appeared was the entire display for the first
one along with a value of 0.
So, here is my question. How can I transfer information within the AJAX
call, other that the entire bottom display which works fine, so that I
can do the post-processing to either hide or show the edit button.
I thought it might be an "imprinting " of this hidden variable, but it is
not. I moved that piece of code out of the inital page build and only
appearing in the AJAX call. Of course, the hidden variable didn't show
up at all since the view source only showed the results for the first
one which did not use the AJAX call.
I implemented a rather "dirty" way and it worked. I prepend the entire
return from AJAX with either a 0 or a 1. On the return, I separate the
two, and then innerHTML with the string start at position 1 and use the
first value for show/hide. However, I was wondering if there is a
better, cleaner, way.
Comment