setting a javascript value for a variable

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

setting a javascript value for a variable

Post by pilandros » 2015-06-10 23:27

I am trying to implement a "tablename-dv.js" customization code.

On the on-line manual, in the "magic files in the hooks folder" section it talks about dealing with the Prototype Javascript Framework, and there is a sample code to figure it out how to deal with it.
I need to set a value for a date-field depending on another field value, so I used the suggested code showed in the manual like this:
document.observe('dom:loaded',function() {
$('field').observe('change',function(){
...
}
}
I finally figured out how to setValue to a js variable by using a sentence like this: Format.Element.setValue('field',value);

My problem is with date type variables, since setting a value to a date-type variable does nothing at run time.

I browsed the tablename_dml.php file and saw that each date-type variable is segmented into 3 $_Post variables (year, month & date), so I guessed that maybe I needed to setValue to each of those 3 variables, tryed but nothing happens.

What can I do to set a new value at run time to a date-type variable?
Thanks for any help

PD. I am using the 5.40 version

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: setting a javascript value for a variable

Post by shasta59 » 2015-06-11 01:08

See my post here. This may help you.

http://forums.appgini.com/phpbb/viewtop ... 4469#p4469

Not sure if it will but I use this code to put in a 1 or 2 based upon a response in another field. You could adapt it to do what you want. The article explains where to put the code. It used jquery to do it.

Hope this helps

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: setting a javascript value for a variable

Post by pilandros » 2015-06-11 15:24

shasta59 wrote:See my post here. This may help you.

http://forums.appgini.com/phpbb/viewtop ... 4469#p4469

Not sure if it will but I use this code to put in a 1 or 2 based upon a response in another field. You could adapt it to do what you want. The article explains where to put the code. It used jquery to do it.

Hope this helps

Alan
Thanks so much for your response.
Since the field I am trying to set a value is a date type I am afraid that my problem has to do with showing the value through the datepicker function. In other words, I am pretty sure the variable does get a new value but is not showing it because I have tryed to set a new value on the fly with a plain varchar type field using the same expression and it does set a new value and it shows it. (The test I made was to set the date value into a varchar type field to check if my routine was working and it did set the date value from my routine, confirming my date calc routine is doing what it was intended to do; problem is with the date-type field that is not showing the new value)
So checking the tablename_dml.php script file I have noticed that date-type fields has 3 sub-set variables named xxxYear, xxxMonth, xxxDay probably updated by the datepicker function and the tablename_dml.php file sets the final field value by adding the values of these 3 variables, ie. xxx = xxxYear + '-' + xxxMonth + '-' + xxxDay prior to the sql setence.
So, thats why I tryed to set the value for those 3 variables instead, but the Prototype javascript framework does not recognize them probably because I am using the wrong variable names?, I don't know.

Once again thank you Alan for your promptly response.

Jorge

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: setting a javascript value for a variable

Post by shasta59 » 2015-06-11 15:35

I just looked a little more at the structure for date storage and setting and there is a way to do it.

But right now I do not have the time to even look at this situation.

But I do know it is very possible to do and have it work properly.

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

dnetware
Posts: 7
Joined: 2014-12-24 17:08

how to design

Post by dnetware » 2015-06-11 17:15

Hello please can someone guide me on how to design a dynamic website using appgini because am new to it. I need a step by step way of doing it. Can someone please put me through.
Thanks

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: setting a javascript value for a variable

Post by pilandros » 2015-06-11 17:27

shasta59 wrote:I just looked a little more at the structure for date storage and setting and there is a way to do it.

But right now I do not have the time to even look at this situation.

But I do know it is very possible to do and have it work properly.

Alan
Again, Thanks so much Alan for your time and effort to respond. I appreciate it.
If you just guide me on which of the scripts I should look for to edit (not details just which should I browse), I will be more than thankful and I will do my best to look for a solution and show it here for the AppGini community.
Thanks again Alan.

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: how to design

Post by pilandros » 2015-06-11 17:38

dnetware wrote:Hello please can someone guide me on how to design a dynamic website using appgini because am new to it. I need a step by step way of doing it. Can someone please put me through.
Thanks
Well, for what I can tell you from my own experience is that Appgini IS THE TOOL to design a dynamic website (and by the way is the easiest to understand) designed for the DO IT YOURSELFer. But, you have to know what you are looking for or what are you expecting to get from a "dynamic website". Otherwise you will be jumping around without getting to nowhere.
My humble advice is to give it a try figuring out what you should need to track down your expenses or to setup a list of your recipes and see what you get from that.
Then if you feel lucky go on with one of the ready made sample apps (you can get them here: http://www.bigprof.com/appgini/free-ope ... plications).
But, if you can get nothing from the first step; You should get some consultant's advice for whatever you need. If you are at this point and your job or your customer depends on the results of this venture I strongly recomend you to get professional advice; It will be always cheaper than trying yourself.
Hope this will help you.
Good Luck

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: how to design

Post by pilandros » 2015-06-11 17:49

dnetware wrote:Hello please can someone guide me on how to design a dynamic website using appgini because am new to it. I need a step by step way of doing it. Can someone please put me through.
Thanks
Oh yes, there are several nicely edited videos to watch and learn. See them here: https://www.youtube.com/user/appgini5

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: setting a javascript value for a variable

Post by pilandros » 2015-06-11 21:09

FOUND IT.

if you need to set a new value for a date-type variable at run time with a javascript routine, you need to set 3 separate variables instead.

Say your date field is called start_date, if you need to set a new value for start_date to be 2016-11-20 you will need to do it as follows:
(using de Prototype Javascript Framework) your routine will have to set the values for year, month and day separately. ie:
...
var vyear=2016, vmonth=11, vday=20; // as for 20th of November, 2016 or 2016-11-20
Form.Element.setValue('start_date',vyear); // the year portion variable is named the same as the field name
Form.Element.setValue('start_date-mm',vmonth); // the month portion variable is named with the field name + "-mm"
Form.Element.setValue('start_date-dd',vday); // the day portion variable is named with the field name + "-dd"
...
and that's it!
(still testing for database results, but I think I got it solved)

Remember, I'm using ver 5.40

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: setting a javascript value for a variable

Post by shasta59 » 2015-06-12 16:39

That is great!

Here is a mod I made to my script to test the putting in of values into a date field using jquery

It is strictly a variation on the code I posted in viewtopic.php?f=8&t=1684&p=4469#p4469

By way of a quick explanation

if the value put into visitors (the field which determines what goes into the date field) is equal to test it puts a 10 (or October) into the month field of the date field. If not it puts in February or a 2. You could change this to be anything you want. You could eliminate the else statement or do whatever you wish. It all depends on what you want put into the date field based upon the input of another field.

Code: Select all

<script>
	
	$j(document).ready(function(){
	$j('#visitors').change(function(){
	var visvalue = ($j('#visitors').val());
	if(!visvalue || visvalue == 'test'){
	$j('#game_date-mm').val("10");
	}else{
	$j('#game_date-mm').val("2");
	}
	});
	});
	</script>
Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

dnetware
Posts: 7
Joined: 2014-12-24 17:08

Re: setting a javascript value for a variable

Post by dnetware » 2015-06-12 16:47

How to design:
Can I get a writing document on how design a website using appgini, I don't like videos cos I love reading and applying the effect.
Thanks guys.

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: setting a javascript value for a variable

Post by shasta59 » 2015-06-12 17:21

Can you start this in a new topic please then I will post an answer. This question does not follow the topic.

Thanks
Calgary, Alberta, Canada - Using Appgini 5.50 -

User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

Re: setting a javascript value for a variable

Post by pilandros » 2015-06-16 17:18

shasta59 wrote:That is great!

Here is a mod I made to my script to test the putting in of values into a date field using jquery

It is strictly a variation on the code I posted in viewtopic.php?f=8&t=1684&p=4469#p4469

By way of a quick explanation

if the value put into visitors (the field which determines what goes into the date field) is equal to test it puts a 10 (or October) into the month field of the date field. If not it puts in February or a 2. You could change this to be anything you want. You could eliminate the else statement or do whatever you wish. It all depends on what you want put into the date field based upon the input of another field.

Code: Select all

<script>
	
	$j(document).ready(function(){
	$j('#visitors').change(function(){
	var visvalue = ($j('#visitors').val());
	if(!visvalue || visvalue == 'test'){
	$j('#game_date-mm').val("10");
	}else{
	$j('#game_date-mm').val("2");
	}
	});
	});
	</script>
Alan
Great explanation and for an alternate solution Alan. I'm sure we will all appreciate that.

Post Reply