Welcome, Guest! Registration


Friday, 2019-02-22
Main » 2012 » March » 24 » How to set default checkboxes in Ucoz forms
2:31 AM
How to set default checkboxes in Ucoz forms

Having to click same input checkmarks at Ucoz "New / Edit Entry" forms on each save was quite annoying. So I decided to set some defaults.

When opening a form for "Add new entry" / "Edit" I wanted "Substitute line feeds by the tag <BR>" to be always unchecked, "Receive notifications about comments" to be always checked, and a bunch of other checkmarks to be always checked too.

Luckily, there is jQuery availably out of the box. I chose to go with 1.6.1. The idea is to use JavaScript / jQuery to set the defaults by the ids of the checkmarks, once the document is ready. It was easy to identify the proper ids with MS Expolrer's Developer Tools, Firebug in Mozilla Firefox would have been helpful too.

Here is the code:

<script type="text/javascript">
if ($("#addEntForm")) {
  $("input#format_brief").attr('checked', false);
    $("input#format_message").attr('checked', false);
    $("input#showa").attr('checked', true);
    $("input#sbsc").attr('checked', true);
    $("input#comsa").attr('checked', true);
    $("input#uto").attr('checked', true);

Here are some gotchas:

Ucoz modules, such as Site Catalog (Links), File Catalog, Publisher have dedicated html templates for their "Entry adding/editing page"; but this is not the case for Blog! After stranding around the templates section at the Contol Panel I ended up adding the script to the "The first container" which is the section on the right-side of all pages of this site.

In all other cases I would put the code to a file and use

<script type="text/javascript" src="..."></script>

for only the "Add/Edit" pages, I could also have thrown away the "if" in this case.

There is another thing to be aware of, - Ucoz automatically includes jQuery always at the end of the <head> section, which means your jQuery scripts got to be placed somewhere after <head></head>, which is not totally right, but as long as it works - I am Ok with it.

Views: 1751 | Added by: loc2logg | Tags: forms, uCoz | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]