This is an archival post from my newsletter. Join the newsletter to get in the loop.

Creating a Dynamic List in Javascript

I thought I’d publish this code out to the world in hopes someone else may find it useful. I’m sure there are optimizations that could be made and I’d love to hear them.

This is a piece of code I came up with for our upcoming product HelpSpot which is a PHP driven Help Desk program. One of the key features is the ability to tag requests with what we call “reporting tags”. Each request can have tags associated with it. Later these tags can be used to build very flexible reports on where your requests are coming from, what the major issues are, etc.

Since people would probably be adding lots of tags I wanted to come up with a good way of getting the input without either a request back to the server each time they added one or making them use a textbox and giving lots of instructions about how there should only be one per line, etc.

So this is what I came up with. You can find an example here. It creates a nice simple list on the fly. Each list item gets a hidden form field that in PHP will be passed back as an array of list items. Then I can insert them into the database and so on. This should work on IE6 and all Mozilla’s cross platform. It’s still being tested and worked on. If we make any major revisions I’ll post them here.

Join my mailing list

Join my mailing list and get a copy of my ebook, Securing the Five Figure Sale, for free. Instantly.