This topic is locked
[SOLVED]

 Working with JavaScript Onload

9/12/2010 7:28:03 PM
PHPRunner General questions
ladykathleen author

I was trying to work with the JavaScript Onload and I can't get it to work.
I tried modifying the example off this page http://xlinesoft.com/articles/amount_to_single_field.htm

but not sure what I am doing wrong.
Well let me start at the beginning with what I am needed and maybe someone can help me.
On the add Page I want to be able to enter one date (say Monday) and then auto fill the rest of the week for 7 days total
Then I want to take Time A and Time B and auto calc the amount of time.
Then I want to do other calcs on Amount of time but I think I can figure that out if I can get the first two figured out
I understand some programming but have never played with JavaScript and I am a bit new to PHPRunner but have been able to figure out most things I needed from the site and forum. So that is why I am asking for your help here in the forum.

And the not getting it to work part above is I can't even get anything to show up in the field when adding a new form, just asks like normal manual entry.
Thanks in Advance

Admin 9/13/2010

I'm not 100% sure I understand what kind of calculation you need to perform.
If you are looking for a way to calculate date/time difference in Javascript here are few examples:

http://www.javascriptkit.com/javatutors/datedifference.shtml

http://psoug.org/snippet/Javascript-Calculate-time-difference-between-two-dates_116.htm

ladykathleen author 9/13/2010



I'm not 100% sure I understand what kind of calculation you need to perform.
If you are looking for a way to calculate date/time difference in Javascript here are few examples:

http://www.javascriptkit.com/javatutors/datedifference.shtml

http://psoug.org/snippet/Javascript-Calculate-time-difference-between-two-dates_116.htm


On the date I just need the JavaScript Onload to look at one date and then change the another date to add one day.

Example

DateA and DateB

When on the Add Page a person changes DateA to be 1/1/2010 I would like DateB to automatically change to 1/2/2010.

------------------------
On the Time Calculations I finally got most of that figured out with some help from support. They got me headed in the right direction.

I am having trouble figuring out one small thing.
I would like to put an IF ELSE statement in the script and I am not sure of the syntax

what I need is:

If TimeB < TimeA then DO this Else Do That
And help is apprecated as I am just learning the syntax for javascript while using phprunner.
Thanks

Kathleen

ladykathleen author 9/13/2010



On the Time Calculations I finally got most of that figured out with some help from support. They got me headed in the right direction.

I am having trouble figuring out one small thing.
I would like to put an IF ELSE statement in the script and I am not sure of the syntax

what I need is:

If TimeB < TimeA then DO this Else Do That
And help is apprecated as I am just learning the syntax for javascript while using phprunner.
Thanks

Kathleen


This part I was finally able to figure it out. Thanks to the forum, there was enough clues
Still need help with the Date thing

ladykathleen author 9/14/2010

Thanks to the supprt team, they answered my questions and not I can move on to the next items.

R
rod 9/15/2010



Thanks to the supprt team, they answered my questions and not I can move on to the next items.


Hi Kathleen,
I am also trying to absorb the JavaScript Onload event and can't seem to get it to work. Would you be so kind as to share what you have discovered to make this work? I am wanting to take a field "code" and have JavaScript automatically populate another field, "URL" on the add page when the user enters the "code" field. Close to the Price/Horsepower = Tax example, but from a database lookup for the "URL".
Many Thanks,

ladykathleen author 9/15/2010



Hi Kathleen,
I am also trying to absorb the JavaScript Onload event and can't seem to get it to work. Would you be so kind as to share what you have discovered to make this work? I am wanting to take a field "code" and have JavaScript automatically populate another field, "URL" on the add page when the user enters the "code" field. Close to the Price/Horsepower = Tax example, but from a database lookup for the "URL".
Many Thanks,



Rod,
I am not sure what part is not working for you, and I say that only because I found with the code I was using it was simple things that broke mine before I got it working.
I can tell you some of things that helped me.

If you have more than one funtion func() make sure they have unique names.

in the ctrlA.on('change', func); statement the 'change' worked better than using 'click' for most my needs.
If you send me a sample of the code your working with I might be able to help you with it better.
Kathleen

R
rod 9/16/2010



Rod,
I am not sure what part is not working for you, and I say that only because I found with the code I was using it was simple things that broke mine before I got it working.
I can tell you some of things that helped me.

If you have more than one funtion func() make sure they have unique names.

in the ctrlA.on('change', func); statement the 'change' worked better than using 'click' for most my needs.
If you send me a sample of the code your working with I might be able to help you with it better.
Kathleen


I think I will need to talk with support. Turns out that I am using a lookup wizard / lookup table / selection box for my primary field, and I found out that if I make a selection, then mouse click on another field, it does not function. However, if I tab into or out of the selection box, or hit the enter key, it works? Weird.
Here is the JavaScript code I am playing with: (The ECN value is a temporary MySQL Alias field which might have something to do with the weirdness)



var ctrlUP_to = Runner.getControl(pageid, 'UP_to');

var ctrlECN = Runner.getControl(pageid, 'ECN');

function func() {

ctrlECN.setValue(parseFloat(ctrlUP_to.getValue()));

};

ctrlUP_to.on('keyup', func);


I will still need to solve how to do a database lookup from my ECN table ID in the above Java Script code.
Rod

ladykathleen author 9/16/2010

Rod,
On the part you are talking about I kinda have the same trouble with the Date thing I was doing. If someone enters the date the other date will pop in, but if you use the calander pop up it does not until you click into the field then out. So if you get that part solved on yours I would love to see it too.
If I figure it out I will send you how I get it done.
On my code for the calaculations I used the selcet by drop down look up but not the lookup into another field. but mine was based on the field box they were currently in not the field being changed.
I will look at your code again this afternoon when I have more time to play with it.