Forums

javascript help needed

daffy 29 Mar, 2009
Hi I have a chronoform with two date pickers, set to use Y-m-d as date format.
I want to use javascript to get the duration in days between these two dates and then enter it as a hidden value in the form.

I have almost no knowledge of javascript (or for that matter of PHP0 but I am struggling with it).
I have put this
   
var date1 = new date(y1,m1-1,d1);
var date2 = new date(y2,m2-1,d2);
var today = new date();
var oneday = 1000*60*60*24 ;
function duration(date1,date2){
  return (date2-date1)/oneday +1;}
function errd1{
  return (today > date1);
}
function errd2{
  return (date1 > date2);
}

in the 'javascript bit of the form code.
The question is 1.
how do get from the form, the values of y1,m1,d1 and y2,m2,d2 to use with the javascrpt ?
question 2. how can I put the result as the value of the hidden element and
question 3. is my javascript code anything like correct !!
I will want also to check whether the first day is before today and reject the form if so
and to check that the second date is not before the first.

Help on these issues please. !! http://www.chronoengine.com/forums/posting.php?mode=post&f=2#
--
Dave
Max_admin 30 Mar, 2009
Hi Dave,

why JS ? do you need the result before the form is submitted or after it is ?

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
daffy 30 Mar, 2009
Thanks Max,
I am aware of my ignorance. But I wanted to include the value of 'duration' the length in days between the two dates in the form data. Also I wanted to warn the user as soon as possible that the first date should not be before today nor the second date before the first. This is validaton I suppose, But people do do silly things.
I can do it after the data is stored I suppose but this gives a longer delay.

--
Dave
Max_admin 30 Mar, 2009
then its better to do it the JS way!

I will try to answer your questions!

#1- do you have the date fields as calendar ? chronoforms calendar ? if so the nmootools is loaded and we can use this:

$datepieces = $('datefield').value.split("-");


$datepieces will be an array now, holding the 3 parts of the date, assuming your date format was d-m-y then $datepieces[0] will hold the d (day)

#2- same way,
$('resultfield').value = result;


#3- I think so, JS needs debugging, and needs Firebug for Firefox to save your time and prevent you from getting a headache quickly!🙂

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
daffy 30 Mar, 2009
Thanks very much Max I will work on it.
--
Dave
GreyHead 01 Apr, 2009
Hi Dave,

Just back from a trip and catching up on the forums here.

I posted code to do date checking with two date-pickers a couple of months ago. It was for a booking application so we checked that the departure date was after the arrival date and also calculated the duration I think.

Bob
daffy 06 Apr, 2009
Hi Bob, Thanks for taking an interest in my problems.
I did track down the item you referred to above. It was a reponse to a post by iaweb dated Fri Jan 30th.
But it was a muh more complex situation than I have. But I will extract what I can from it.

Anyway I am still bamboozled by Joomla, and beginning to feel Perhaps I made a bad choice.

But can you tell me are there any reasons why using stored programs in a jos_xxx database is bad ?
I have in mind to let chronoforms do much of the user interaction then do the program logic by stored programs.

So that when chronoforms 'inserts' a record into the database a triger starts all sorts of other machinations.
--
daffy 06 Apr, 2009
Sorry about that.
The submission when off before ready because my finger slipped !
Thanks for any help.
--
Dave
Max_admin 07 Apr, 2009
Hi Dave,

you can do anything after the data is inserted, any examples of machinations ?

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
daffy 07 Apr, 2009
Thanks max.
Here is one of several strored progs transferred from firebird database to MySql
This is a very simple case. jos_2ee_diary holds a day by day account of items hired.
chronoforms sets date1 and date2.
This routing is just a select procedure which get the max booking over the dates of any stock item.

Procedure getMax(IN date1 date,IN date2 date, IN stock_id int,OUT Maxcount int)
 select max(thecount) from jos_2ee_diary d where d.theline = stock_id and d.thedate between date1 and date2;
end

Now instead of parameters Date1 and Date2 I should like to use directly the chronoforms generated table

Procedure getMax(IN stock_id, OUT Maxcount)
  declare startdate date;
  declare enddate date;
  select date3 from jos_chronoforms-dates into startdate;
  select date4 from jos_chronoforms_dates into enddate;
  select max(thecount) from jos_2ee_diary d where d.theline = stock_id and and d.thedate between startdate and enddate;

Then once the chronoform is completed I just need to 'call getMax(xx)' as an sql somewhere I hope !!

Is this a safe procedure in Joomla ??
Thanks for your thoughts
--
Dave
Max_admin 09 Apr, 2009
Hi Dave,

I think that as long as this code runs fine through any PHP then it should work fine, just use the built in Joomla codebase for dealing with the database, its easy and better to use in Joomla!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
daffy 10 Apr, 2009
Thanks Max,
I did not want to spend lots of effort writing stored programs then find that they were not reliable in Joomla.
I have used databases for years and as a learner I have several books about PHP and Javascript etc But then I find that Joomla does it differently !!
Are there any good books about the detailed workings of Joomla ?
--
Dave
GreyHead 10 Apr, 2009
Hi Dave,

Joomla just provides an interface to the PHP+MySQL code that is a little bit simpler and more protected than 'raw code'. Behind the scenes it is for the most part just executing standard PHP+MySQL commands.

There are a few Joomla 1.5 books out now but I'd hesitate to mark any of them 'good'. I have Dan Rahmel's 'Professional Jomla!' on my desk here (whcic is the best that I can find) but I rarely refer to it. It's easier to go to the PHPDocs documentation or, increasingly, the Joomla dev wiki is starting to have more useful articles. I wrote one here on the MySQL results methods just because I kept on needing to check them out.

And feel free to ask here too - we'll try and help.

Bob
daffy 10 Apr, 2009
Thanks Bob,
I have Dan Rahmels Book and I find I have a printout of your article 'why should I use the Joomla database class' on file and to hand'
Probably the greatest snag is my lack of familiarity with PHP and with Javascript and their interchangeability.
I just came back from your department by ferry yesterday and will be back again in a few day's time.
--
Dave
This topic is locked and no more replies can be posted.