tags:

views:

36

answers:

1

I wrote a JavaScript script that swaps two selected img tag src values.

The point is to let the user rearrange a list of images.

For sending the new order to a PHP script, I have two ideas:

  1. Have a button execute a JavaScript function that gathers the new order of images into an array of URLs. Then, rely on JavaScript to send the data to a PHP script?

  2. Have the initial JavaScript rearrange hidden input tag value attributes which would contain data such as a URL and order number. Then, rely on a submit input button to execute a POST request without JavaScript?

Thanks!

+1  A: 

Why not consider using Jquery's UI Draggable/Sortable? It takes some of the brain damage out of the code and gives the user an intuitive way to interface with the reordering process:

http://jqueryui.com/demos/draggable/#sortable

You could then use the callbacks to update via Ajax, or set variables that could be dumped to PHP on submit.

bpeterson76
Well, my script is finished, so I'll hold on to it for now. I might look into jQuery for my next project, though. Ultimately, my question is whether using Ajax to send the data to the PHP script is reliable, or if I should rely on form items instead, in case Javascript is not enabled.
letseatfood
I recently worked on a project where we redesigned/rebuilt over 100 websites for the federal CARD act regulations on credit cards. The bank was over the top on requirements for useability, accessibility, etc. For example, we had to design UI's that were useable with CSS AND images turned off.....crazy overkill. Yet they used Javascript to submit their forms.In many cases JQuery is very backwards compatible...one outstanding example is http://datatables.net/ which will gracefully degrade to properly formatted HTML if javascript is disabled. Obviously, it depends on the plugin.
bpeterson76