Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Alert Message onClick Client Script

salvadormarchan
Kilo Guru

good morning All,

I need some help on how to make an alert message when the user tried to click on a read-only textbox.

In the Client Script, I don't see onClick option. (note: this is follow up to this forum link correspondences: Textbox and Icon of glide date time Fields)

Thank you again!

Dor

1 ACCEPTED SOLUTION

twofirstnames
Kilo Expert

Hi Dor

Try the following:



function onLoad() {

$('change_request.start_date').observe('click', respondToClick);
$('change_request.end_date').observe('click', respondToClick);
$('change_request.work_start').observe('click', respondToClick);
$('change_request.work_end').observe('click', respondToClick);

function respondToClick(event) {
alert('Please use corresponding calendar icon when choosing dates.');
}

}


Cheers
Dale


View solution in original post

8 REPLIES 8

adiddigi
Tera Guru

The script should be something like this,



var startDate = $('change_request.start_date');
startDate.onclick = "clickMe()";

function clickMe(){
alert('oops, you just clicked a read-only field');
}


Hi Abhiram,
Thanks for the tip...I tried it but it seems that I'm still missing something. Here's my code right now:

Type: onLoad
table: change_request
Active: true
GLobal: true
Inherited: true
//===========================================================================
function onLoad() {
try {
var startDate = $('change_request.start_date'); //Planned start date
startDate.readOnly = true;
startDate.style.color='black';
startDate.style.backgroundColor='#F0F0F0';
startDate.onclick = "dontClickReadOnly()";

var endDate = $('change_request.end_date'); //Planned end date
endDate.readOnly = true;
endDate.style.color='black';
endDate.style.backgroundColor='#F0F0F0';
endDate.onclick = "dontClickReadOnly()";

var workStart = $('change_request.work_start'); //work start date
workStart.readOnly = true;
workStart.style.color='black';
workStart.style.backgroundColor='#F0F0F0';
workStart.onclick = "dontClickReadOnly()";

var workEnd = $('change_request.work_end'); //work end date
workEnd.readOnly = true;
workEnd.style.color='black';
workEnd.style.backgroundColor='#F0F0F0';
workEnd.onclick = "dontClickReadOnly()";

function dontClickReadOnly(){
alert('Please use corresponding calendar icon when choosing dates.');
}

} catch(e) {

}
}
//=================================================================

I tried placing the dontClickReadOnly function outside the scope of onLoad function and outside the try-catch block but no difference (when I tried clicking the textbox of any of the dates, it would not show the alert message.)

Appreciate your response again (as well as other's response)...

Dor




My bad, I am so sorry Dor.I tried it in my instance as well and it doesn't seem to be working. But i remember using it and thats the reason i had replied to your post. I guess thats because, all these fields have default handlers defined, and so we are not able to override it. I will wait for some expert to reply!


No worries...I'm looking at javascript APIs (http://api.prototypejs.org/) and other forums and hopefully I may find a tip somewhere...