Posting an active list item

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Paranoid
Forum Newbie
Posts: 12
Joined: Mon Nov 09, 2009 7:54 pm

Posting an active list item

Post by Paranoid »

Right, I have been trying to look around and see if there's anything similar but I haven't been lucky as the main problem is describing what I want to do...

In simple words:

- I have a list with certain values retrieved from a Database that can be edited in place by users and saved back to the Database.
- The values of the list items can be used to retrieve certain information from a set of options that apply for all of them. For now, this is done by manually entering an items name into an input field and then clicking the relevant buttons to retrieve the information.

So it looks a bit like this:

list_item1
list_item2
etc...

Options in the form of buttons: 'Get name', 'Get surname' etc.

What I want to do is avoid the manual typing of the list items and rather, for example, when I single click (double click is reserved for edit in place) on a list item the input field automatically is filled up with the items content.

Any help will be appreciated.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Posting an active list item

Post by omniuni »

OK, I think I know what you're getting at. To do this, you need to do a few things.

First, create a .php file that returns ONLY the data you want to display. So, for example, iteminfo.php?id=1234 will return the HTML for displaying information on 1234. No <html> or <body> tags, or anything, just the pure HTML for displaying the item in the box.

Now, create an AJAX object. Look around on the 'net, you'll find the code for this that creates an object that will work in all browsers.

Now, add an onChange event to your list, that triggers a function that calls the AJAX object, retrieves information for the item, and use the innnerHTML function to replace the contents in the box with the information on the item.

Does that help?
Paranoid
Forum Newbie
Posts: 12
Joined: Mon Nov 09, 2009 7:54 pm

Re: Posting an active list item

Post by Paranoid »

Thanks for the reply, I actually forgot to enable e-mail messages when a new post is written on this thread and I pretty much figured it out by myself, using a methodology really similar to what you just described. It took me an extra day or two, but at least it's done now!

I also tried using jQuery's Selectable component which did exactly this but that didn't go very well as I kept having trouble with my window.onload events, and as I found out there's some conflict issues with jQuery and onload events unless everything is implemented using jQuery.

Thanks again.
Post Reply