View Full Version : AJAX with JSMX: Inserting additional forms

08-30-2006, 07:34 PM
I'm working on a course registration system where I have a form with several selects layed out in a row. I have a JavaScript function set as a handler for onChange for each of the selects. When a new value is selected the function uses JSMX to query the server. The JSMX callback function then refills the remaining selects with the appropriate options based on the results from the query. After a valid option has been selected in each select from left to right then a course offering has been chosen. At that point the server can make appropriate changes to the database. The system is working well, but it's time to take it to the next level.

I would like to be able to add additional sets of selects dynamically so that I can allow my users to register for multiple courses. I've thought of a couple of possible solutions, but being new to JavaScript I'm not sure which is the "best" (for some value of best <grin>) way to go about things:

1. Use a table in a single form. When I need to add an additional registration add another row to the table with all of the selects that I need.

2. Use a separate form for each set of selects. When I need another row just insert another form. One possible problem here is that there isn't an easy way to then submit everything. I don't think that will be an issue in my case, however, as the database will be incrementally updated. The final "Confirm Enrollment" button will then change a flag on all of the in-progress records for that particular user.

What is the cleanest way to insert these additional elements?

In both cases one problem I see is being able to uniquely identify the inserted element so that I can make sure I'm reading from and setting the correct selects. I think that the solution to this is to pass the id of the select in to the first JSMX call and then use document.getElementById('id').parentNode.getElementById('otherSelectThatINeedToRead').value to get the correct values. Does that make sense?

Is one of these the preferred way to do this? Is there something entirely different that I should be doing?

Thanks! =)