Rules for writing javascript

Home / Support / Manuals / Administrators Guide /

Rules for writing javascript

Manual in PDF format

1. Spaces, tabs and newlines

  • We use spaces between “if” and the left parenthesis, to the left and right of the “=” sign, after the comma as a separator for variables or function parameters etc.
  • We use tabs to indent the code from the left margin of a new line. The tab represents two consecutive spaces, and is a shortcut key for inserting them into the code in the javascript editor. Each code dive requires one tab – two spaces. We do not indent the source code at the first level.
  • Enters – transitions to a new line – we use before the left parenthesis ”{“ and after it, as well as before the right parenthesis ”}“ and behind her.

Obrázek.png

  • Bad example

Obrázek.png

2. Simple apostrophes

  • We always use single apostrophes as the default delimiter. Because it is possible to combine javascript code with server functions, we always leave double quotes behind server function calls.
  • Server function parameters must often be enclosed in double quotes because the parameter value may contain a comma, which is considered a parameter separator by default. Texts inside double quotes are treated as string constants and do not replace server functions, only variables. The only exception is the parameters of the “SQL” and “SQLARRAY” functions, inside which it is possible to call server functions, even though the parameters of these functions are wrapped in double quotes.

Obrázek.png

Obrázek.png

3. Intermediates

  • Javascript code defined in control events must contain a trailing semicolon.

Obrázek.png

Obrázek.png

  • The only exception is the javascript code used in the “ActionButtons” control for the “Save”, “Delete” and “Back” buttons. This javascript, on the other hand, must not contain a semicolon at the end, because it is used in the condition as a result of the call in the source code of the resulting web page.

Obrázek.png

Obrázek.png

4. Buttons and postbacks

  • Buttons that are set as “Script”, “Print to template”, “Open view page” or “Open edit form” first run the javascript code defined in the “Client” field (may or may not be defined), trigger a postback or submit the form with the “POST” method (sending all the data filled in the form including sending the information about the button that triggered the postback), and on the server side it will run the defined server script. After the script completes, the user is returned to the form, until then the form content is hidden, and the text “Please wait...” is displayed at the top of the form.

Obrázek.png

  • Clicking the button can be called programmatically using the javascript function “bt_Click(string id)”. A detailed description of javascript functions is given in the separate manual JavaScript functions. Only one postback can be called from javascript, i.e. clicking only one button at a time. Calling the “bt_Click” function (and thus the postback) multiple times in a row is evaluated as an error, and NET Genium will only call the first postback in the sequence.
  • The javascript function “form_Update()” is used to update the form, which also uses postback and the hidden “btUpdate” button to update all control elements in the form.