on submit client script to validate if the hours greater than 24

RudhraKAM
Tera Guru

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

find_real_file.png

find_real_file.png

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;

}

}

}

1 ACCEPTED SOLUTION

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;


}



}


View solution in original post

14 REPLIES 14

Raju Koyagura
Tera Guru

Is there any reason to use onSubmit script?


I recommend to use BR on "Task Time Worked" table something like below no single line code is required



find_real_file.png



In the Action tab:


find_real_file.png


Deepak Kumar5
Kilo Sage

function onSubmit() {


var time = g_form.getValue('time_worked');


if( time ) {


var day = parseInt(time.split(' ')[0], 10);


if( day > 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);


return false;


}


}


}


Thanks Deepak but not helpful


function onSubmit() {


var time = g_form.getValue('time_worked');


if( time ) {


var day = parseInt(time.split(' ')[0], 10);


if( day >= 1 ) {


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;


}


}


}