Adding javascript event using formWizard

La LandShark 24 Feb, 2012
Total noob here, so any help is appreciated.

I have a form that I am editing in advanced mode. I want to add an onBlur() event to one of the fields in the form. I've successfully added the javascript that I want executed via the Load JS event, but how do I actually add the onBlur event to the textbox on the form? I can do it the "non-wizard" way by editing the code itself, but then when I go back and do anything in the wizard and save it that code gets over-written.

Thanks!
Gr GreyHead 25 Feb, 2012
Hi LandShark,

Add an id to the element e.g. my_element

Drag a Load JS action into the On Load event and add code like this
window.addEvent('domready', function() {
  $('my_element').addEvent('blur', xxx);
});
Where xxx can be a function name or a function containing the code you want to execute.

Bob
La LandShark 27 Feb, 2012
Bob,

Thanks so much, that was exactly what I was looking for!
ja jan35utr 25 Nov, 2012
Hi Bob,

I tried above solution for my form, but still seem to have done something wrong.

value of FieldId 'postcode' should be changed to caps and removal of spaces

the code I have in LOAD JS:
window.addEvent('domready', function() {
  $('postcode').addEvent('blur', removeSpaces);
});

function removeSpaces(string) {
 return string.split(' ').join('').toUpperCase();

}


could you please tell me what I'm doing wrong?
thanks in advance,

Jan
Gr GreyHead 25 Nov, 2012
Hi Jan,

You aren't passing a parameter when you call the function so 'string' is probably undefined. Please try this JavaScript:
window.addEvent('domready', function() {
  $('postcode').addEvent('blur', removeSpaces);
});

function removeSpaces() {
  $('postcode').value = $('postcode').value.replace(' ', '').toUpperCase();
}

Or, more simply if you only need it on one input:
window.addEvent('domready', function() {
  $('postcode').addEvent('blur', function() {
    $('postcode').value = $('postcode').value.replace(' ', '').toUpperCase();
  });
});

Bob
ja jan35utr 26 Nov, 2012
Hi Bob,

thanks again, it works like a charm.

gr. Jan
This topic is locked and no more replies can be posted.