- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2017 08:09 PM
Hello I need some help in writing the onsubmit client script ,thanks in advance
Requirement is if the user enters greater than 24 in hrs field it should not allow the user to save the value and should throw an error
the on submit script which i tried is
I copied it from other client script
it is stoping me if I use less than 24 hrs too , please correct my script if necessary and the timer field is Out of the box .
function onSubmit() {
var time = g_form.getValue('time_worked');
if( time ) {
var day = parseInt(time.split(' ')[0], 10);
if( day ) {
g_form.showErrorBox('time_worked', 'Time worked for a given day cannot exceed 24 hours! Changes to time worked have not been saved', true);
return false;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 01:03 PM
Use this.
Modified the if condition
function onSubmit() {
//Type appropriate comment here, and begin script below
var a=g_form.getElement('time_worked').value;
alert(a);
var b=a.split(':');
var c=b[0].split(" ");
if(c[0]!=''&& c.length>1)
{
alert("Please enter value less than 24");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 01:03 PM
Use this.
Modified the if condition
function onSubmit() {
//Type appropriate comment here, and begin script below
var a=g_form.getElement('time_worked').value;
alert(a);
var b=a.split(':');
var c=b[0].split(" ");
if(c[0]!=''&& c.length>1)
{
alert("Please enter value less than 24");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 04:26 PM
Thanks Majumder
but I have an issue after using this on-submit client script ,every thing is working fine except one issue ,please see the below image , if i add 24 hrs and save it ,it is working fine but after that if i add 2 hrs then the total would be 26 hrs so its showing an error .
Client script which i used is
function onSubmit() {
//Type appropriate comment here, and begin script below
var a=g_form.getElement('time_worked').value;
//alert(a);
var b=a.split(':');
var c=b[0].split(" ");
if(c[0]!=''&& c.length>1)
{
//alert("Please enter value less than 24");
g_form.showErrorBox('time_worked', 'Time worked for a given day cannot exceed 24 hours! Changes to time worked have not been saved', true);
//g_form.showErrorBox('Time entered is more than 24 hours');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 05:59 PM
i believe yoy may need to use a flag field for this to store the earlier value as the oldvalue variable of onchange client script maynot work here. Let me go share the updated one tomorrow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 08:57 AM
Did you get a chance to see the issue ?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 01:06 PM
Hi Kamila,
Realy sorry i got stuck with something else, i will work on it as soon as I get time.
In the mean time you could look at using the oldValue and newValue variables in the onchange script.