views:

229

answers:

1

We use a DHTML calendar picker that only allows you to change the date, which is desired functionality. However, I need to figure out the javascript to change the date next to the calendar picker, as seen in the image below, and popup an "are you sure" message.

date example

The above image is one row in a table, so the JS needs to be aware of which one of potentially 10+ dates it should be editing.

I'm a bit of a javascript n00b. Still learning new things. Feel free to link me to things to read and tips/hints/etc.

If it helps any, we're using PERL with CGI. I guess the JS will have to have an AJAX call to update the database, which I can figure out from other examples in the code base. I just need to figure out how to edit the date on the page for now.

And for clarification, the process is... the person clicks on that calendar icon, gets a DHTML date picker, chooses a date, confirms he wants to change datetime1 to datetime2, and then the change gets applied to the text you see next to the calendar icon and gets put in the database.

+1  A: 

Having the actual web page (HTML & JS) would really help here. But, in general, you'll need a way for the JS to "address" the text you'd like to change. The easiest way I know is to wrap the text in a DIV or SPAN, with a unique ID ("datetime1", "datetime2", etc.).

Then, assuming you know which piece of JS is being called when the datepicker runs, access the text item like:

document.getElementById('datetime1').innerHTML = (insert new datetime here);

You'll need a way to pass the ID (datetime1, etc) to the JS, but that should be easy if Perl is generating the 10 datetime rows (i.e., the FOR loop in Perl just sticks in sequential IDs into the DIV/SPANs and again as arguments to the datepicker function).

I assume you know (or can find) how to do "alert()" in JS, so the confirmation should be the easiest part.

It also sounds like you need to send the new dates back into some DB. I suggest a FORM to send it all back to the Perl CGI, which will have to update the DB. Folks more clever than me might be able to tell you how to do that in JS w/ AJAX, etc.

jimtut
(sorry, I cant seem to get the comments to include line breaks...) I would have posted the page but it's for a proprietary system owned by my employer. :(You're on the right track though with what I need. I've included a hidden form and I will use some JS to POST the info back to my PERL scripts.For the hidden form, should I just use onChange to AJAX back the new date? So when they click the datepicker, it'll update the hidden form field after they confirm the change (with the alert), which then sends back the date to the database... does that sound reasonable?Thanks for the help. :)
Ein2015
I haven't used JS to modify hidden form fields, but it should work the same as modifying visible ones (as long as they have unique IDs, it should be easy to access them). So, if you can get the form updated (on the client-side, in the browser), you don't need any AJAX. When they submit the form, your Perl will look at all the form fields, figure out which dates changed, and write the changed values back to the DB (or you can just write all of them back, if you don't mind hammering the DB).
jimtut
Play with the datepicker JS first - make sure you can update the contents of the page. If you can get that working, the back-end Perl stuff should be easy.
jimtut