CheckBox: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
JwellsNB (talk | contribs)
No edit summary
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[file:Checkbox.jpg]]
[[file:Checkbox.png]]


:::::'''Classic                                                   jQuery Mobile'''


== Description ==
== Description ==
Line 9: Line 8:
While a variety of different events are available, a handy response to clicking a checkbox is to call the function <buttonID>_onchange().
While a variety of different events are available, a handy response to clicking a checkbox is to call the function <buttonID>_onchange().


To add a checkbox to your app, choose the Checkbox icon in the Toolbar, then position it on the Design Screen. Use the Property Editor to set the properties you need, then add functions to your code to respond to the events that come from the button: usually, just onchange.
To add a checkbox to your app, choose the Checkbox icon in the Toolbar, then position it on the Design Screen. Use the Property Editor to set the properties you need, then add functions to your code to respond to the events that come from the button: usually, just on change.


== Properties ==
== Properties ==
Line 18: Line 17:
| options || A comma separated list of titles for the checkboxes. (Design time)
| options || A comma separated list of titles for the checkboxes. (Design time)
|-
|-
| orientation  || Horizontal or vertical. jQuery Mobile only. (Design time)
| orientation  || Horizontal or vertical. (Design time)
|-
|-
| getValue(''n'') || Get the value of checkbox ''n'', which will be true or false. ''n'' starts a 1 for the top checkbox. (Runtime)
| getValue(''n'') || Get the value of checkbox ''n'', which will be true or false. ''n'' starts at 1 for the top checkbox. (Runtime)
|-
|-
| setValue(''n'', ''val'') || Sets the value of checkbox ''n'' to true or false. This function should not be called until the checkbox is fully drawn, in Sub Main or later. (Runtime)
| setValue(''n'', ''val'') || Sets the value of checkbox ''n'' to true or false. This function should not be called until the checkbox is fully drawn, in Sub Main or later. (Runtime)
Line 29: Line 28:
Standard [[events|events]] are supported. For this control, the onchange event will be most useful.
Standard [[events|events]] are supported. For this control, the onchange event will be most useful.


== Example (Basic) ==
== Example ==


<pre>
<tabber>
Rem Checkbox Example
JavaScript=
<syntaxhighlight lang="JavaScript">
//CheckBox Example


Function Checkbox1_onchange()
CheckBox1.onchange = function() {
   MsgBox this.id & " is now " & Checkbox1.getValue(1)
  NSB.MsgBox("One is " + CheckBox1.getValue(1) + '\n' + "Two is " + CheckBox1.getValue(2));
}
</syntaxhighlight>
|-|
BASIC=
<syntaxhighlight lang="vb.net">
Function CheckBox1_onchange()
   MsgBox "One is " & CheckBox1.getValue(1) & vbCRLF & _
    "Two is " & CheckBox1.getValue(2)
End Function
End Function
</syntaxhighlight>
</tabber>
Change the text of line 2 of a jQuery Mobile Checkbox:
<pre>
  $("label[for='Checkbox1_2']").text("New Text")                  'jQM 1.4
</pre>
</pre>


== Example (JavaScript) ==
Change the font size of all lines of a Checkbox:
<pre>
  $("#Checkbox1").find("label").css("fontSize","10px")
  $("#Checkbox1").find("label").css("padding-left","35px")
</pre>


Change the background color of line 2 in a jQuery Mobile Checkbox
<pre>
<pre>
//Checkbox Example
  $("label[for='Checkbox1_2']").css("background-color",RGB(255,247,245))                   'jQM 1.4
 
Checkbox1.onchange = function() {
  savethefunction_rvar="";
  _msgbox_confirm(this.id  +  " is now " +  Checkbox1.getValue(1));
  return savethefunction_rvar;
}
</pre>
</pre>


== Output ==
== Output ==


[[file:CheckboxOutput.gif]]
[[file:CheckboxOutput.png]]


[[Category:Language Reference]]
[[Category:Language Reference]]
Line 60: Line 75:


[[Category:jQuery Mobile]]
[[Category:jQuery Mobile]]
[[Category:iWebKit]]

Latest revision as of 13:47, 24 July 2019


Description

The CheckBox is used to display one or more on/off controls.

While a variety of different events are available, a handy response to clicking a checkbox is to call the function <buttonID>_onchange().

To add a checkbox to your app, choose the Checkbox icon in the Toolbar, then position it on the Design Screen. Use the Property Editor to set the properties you need, then add functions to your code to respond to the events that come from the button: usually, just on change.

Properties

Standard properties are supported, plus:

options A comma separated list of titles for the checkboxes. (Design time)
orientation Horizontal or vertical. (Design time)
getValue(n) Get the value of checkbox n, which will be true or false. n starts at 1 for the top checkbox. (Runtime)
setValue(n, val) Sets the value of checkbox n to true or false. This function should not be called until the checkbox is fully drawn, in Sub Main or later. (Runtime)

Events

Standard events are supported. For this control, the onchange event will be most useful.

Example

//CheckBox Example

CheckBox1.onchange = function() {
  NSB.MsgBox("One is " + CheckBox1.getValue(1) + '\n' + "Two is " + CheckBox1.getValue(2));
}

Function CheckBox1_onchange()
  MsgBox "One is " & CheckBox1.getValue(1) & vbCRLF & _
    "Two is " & CheckBox1.getValue(2)
End Function


Change the text of line 2 of a jQuery Mobile Checkbox:

  $("label[for='Checkbox1_2']").text("New Text")                   'jQM 1.4

Change the font size of all lines of a Checkbox:

  $("#Checkbox1").find("label").css("fontSize","10px")
  $("#Checkbox1").find("label").css("padding-left","35px")

Change the background color of line 2 in a jQuery Mobile Checkbox

  $("label[for='Checkbox1_2']").css("background-color",RGB(255,247,245))                   'jQM 1.4

Output