This topic is locked
[SOLVED]

 Checking if a field is populated

2/14/2014 2:24:36 PM
PHPRunner General questions
P
procheck author

Hi,

I'm trying to check a text field to see if it is populated in OnPageLoad. If there is text,

I want to invoke the confirmation. The way my code is below, the confirmation box

is invoked every time. Can someone see my error?
Thanks
Al
var ctrl = Runner.getControl(pageid, 'Notes');
if ((ctrl.getValue !=null) && (ctrl.getValue !=''))

{

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){
if (confirm('You have some notes entered. Do you want to clear them? OK=YES, Cancel=NO')){
ctrl.setValue('');

return true;
}

})};

Sergey Kornilov admin 2/14/2014

You missed parenthesis after ctrl.getValue, makes a huge difference.
ctrl.getValue returns function object, ctrl.getValue() returns the result of this function execution.

var ctrl = Runner.getControl(pageid, 'Notes');
if ((ctrl.getValue() !=null) && (ctrl.getValue() !=''))

{

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){
if (confirm('You have some notes entered. Do you want to clear them? OK=YES, Cancel=NO')){
ctrl.setValue('');

return true;
}

})};
P
procheck author 2/14/2014

Sometimes it just takes a 2nd set of eyes. Thanks Sergey!