PDA

View Full Version : javascript/PHP/DOM question



wyzyrd
05-20-2005, 10:08 AM
I have an odd question that I havent found an answer to in the specs.

If an HTML page (generated by PHP) is changed on client side bu Javascript/DHTML means, (e.g. additional form fields/values added),
do the new DOM entities continue to exist when the form is submitted
(to PHP_SELF) ?

(I want to use Javascript to let user manipulate list contents on client side
then submit changes for DB update and, being a Javascript/DOM dummy,
not sure how to access the new values)

Thanks in advance,
Wyzyrd
<:)}

mwinter
05-20-2005, 11:01 AM
If an HTML page (generated by PHP) is changed on client side bu Javascript/DHTML means, (e.g. additional form fields/values added), do the new DOM entities continue to exist when the form is submitted (to PHP_SELF) ?The name/value pairs of the new form controls should be submitted, yes. However, I have read that sometimes this doesn't happen (with IE, I think), but I can't recall experiencing it personally.


(I want to use Javascript to let user manipulate list contents on client side then submit changes for DB update andThat's fine, but assuming this is for a public environment, you should also be providing a server-side fallback that will perform the manipulation if the client isn't capable of doing so.


being a Javascript/DOM dummy, not sure how to access the new values)You have to remember that the values of option elements are only submitted if they have been selected. Merely existing is not enough.

Though in principle you can use a client-side script to select all of the values prior to submission, the server-side fallback would also need to know what is contained in the select element. What you could do is keep a list of items as session data on the server. If the user uses the fallback to add or remove from the select element, this list can be updated and used during final submission. Any data from the actual element can be ignored.

I'd post some code, but I have no real means of testing at this precise moment in time.

Mike

wyzyrd
05-20-2005, 09:18 PM
Thanks, the info is very helpful :)



That's fine, but assuming this is for a public environment, you should also be providing a server-side fallback that will perform the manipulation if the client isn't capable of doing so.


This won't be for a publicly-viewable service - a LAN/VPN where our customer
(who cares more about style than substance) is in control of browser/version
(otherwise I'd do it ALL server-side)



You have to remember that the values of option elements are only submitted if they have been selected. Merely existing is not enough.


Current design/plan is to use nested <ul> items (names of groups/members of each group) and a table (possible members of the groups and associated data) for a "combo-box" effect .(similar to a contact list with sorting by interest subgroups) The <li> and table row entries will contain <input type=hidden> data items as well as a hidden item-count. Javascript/DHTML on client side will let them "mix and match" subgroup member lists. The PHP code on server side will
insert/delete/modify/fetch DB entries to be displayed.

Seems like it should work, but I wasnt able to find info on whether or not
internal page changes (esp new items) persisted when page was reprocessed server side.

Thanks again
Wyzyrd
<:)

mwinter
05-20-2005, 09:50 PM
Seems like it should work, but I wasnt able to find info on whether or not internal page changes (esp new items) persisted when page was reprocessed server side.Just to be explicit, dynamic modifications client-side will not be transferred server-side, nor will they be stored in the cache. Refreshing also destroys any changes. However, dynamic modifications - such as new form controls - should (bar any bugs) affect client-to-server communications.

Mike