Checkbox UNcheck action

CrystalFrontier 04 Sep, 2014
Dear all

I have received a fully functional code from this forum (Thanks for that!) for a checkbox that, if ticked, waives fees for participants of a tournament. My question is how I can get the originally assessed value back once the box is unchecked (e.g. if it had been checked by accident), because then the values are stuck with the discount value. The code is:

var checkbox_id, textarea_id, checkbox, textarea, div;
/* edit the next two lines to match the ids of the elements in your form */
checkbox_id = 'host_school_y_n';
textarea_id = 'fees';
textarea_id = 'due_oct'
railpass_id = 'railpass'

window.addEvent('domready', function() {
  checkbox = $(host_school_y_n);
  textarea = $(fees);
  duearea = $(due_oct);
  railpass = $(railpass);
  showHide();
  checkbox.addEvent('click', showHide);
});

function showHide() {
  if ( checkbox.checked ) {
    textarea.value = $(due_oct).value;
    duearea.value = $(railpass).value * 25;
  } else {
  }
}


Is there any code I can use as an UNcheck action? Thanks for any help.

Christopher
Max_admin 07 Sep, 2014
Inside the else{} section, you need to do the same calculation to set the full value!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 08 Sep, 2014
Hi Christopher,

I'm not sure exactly what the logic is you are using here but the code that Max suggests will be something like this
function showHide() {
  if ( checkbox.checked ) {
    textarea.value = $(due_oct).value;
    duearea.value = $(railpass).value * 25;
  } else {
    duearea.value = 0; // add code here
  }
}

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