Skip to main content
Known Participant
July 18, 2010
Question

Combining javascript and CF question

  • July 18, 2010
  • 1 reply
  • 904 views

OK, it's finally sinking in that CF processes everything on the server, sends an html page back to the client, and JS does its thing on the client side. I suppose it's confusing because of the way one can intermingle CF code, html, and JS in one big heap of spaghetti. Here's my question: suppose I have a page that receives an ID via the url header, does a query on the ID and pre-populates a form, allows a user to edit the form, and when submitted, has a bunch of code that checks for various conditions and if a particular condition is met, asks the user to confirm the update. Suppose also that I would prefer that the user stay on the same page while the processing is going on and only go to a new page if the submit is accepted. Originally, I had the form submit to a new .cfm page that had all the logic and queries, but am now realizing that I can't call any kind of JS from that page until it finishes processing and the server sends the whole ball of wax back to the client. Right?

So in the limited depths of my understanding, I am thinking that instead, either

A. instead of submitting the form and going to another page for processing, I need to use onSubmit() to initiate all the processing code via cffunction calls, and if a particular condition is met, trigger the JS confirm() function (or jQuery dialog for that matter) and use the results of that to finally submit the form for processing, or that

B. the solution lies within Ajax, of which I know almost nothing.

Thoughts?

This topic has been closed for replies.

1 reply

Inspiring
July 19, 2010

My thought is that this might be simpler than you envisage. What sort of validation did you have in mind?

earacheflAuthor
Known Participant
July 19, 2010

Hi Dan, you're probably right...

first, the db design uses only two tables for this part... an Events table which includes details of the performance, and an EventCalendar table, which has the dates and times of the events as well as Events.EventID as a foreign key. Originally, my plan was:

1) User decides to edit an event, so that EventCalendar.Event ID is passed via URL to

2) The edit/insert page, which when receiving the ID to process, pre-populates the form with the values from a query and

3) When the user submits the form, it goes to a processing page which handles all the logic. Specifically, it's looking to see if

     a) there are multiple performances of this Event in the EventCalendar table and

     b) if the user has edited fields that correspond to fields in the Events table, so changing them will change all performances of that particular event.

     c) and only then, alert the user that editing this one performance will change all related performances.

On reflection, I could do this instead:

1) When the user gets to the edit/insert page with the EventCalendar.EventID, it immediately does

     a) a query to find the related Events.EventID

     b) a query using that ID to find all performances with the same ID

     c) if it finds more than one performance, set a variable for later use, e.g. multiple = true

2) When the user submits, use OnSubmit() to

     a) check whether the variable ("multiple") is true and then

     b) check whether the user has also edited fields that correspond to the Events table.

     c) if so, alert the user.

     d) on confirm, send the form to the processing page, or on cancel, return to the edit/insert page.

Does that make more sense?

Inspiring
July 19, 2010

Are there really fields in the events table that do not apply to all performances?  If so, your data model is probably not what it should be.