javascript - Updating a label based on the selected option using Dojo -
i have specific requirement using dojo framework: based on selected option (<option>
) need update label (<label>
).
i did not find dojo, found similar code using javascript/jquery. example: http://jsfiddle.net/godinall/pn8hz/
can tell me how achieve same thing using dojo?
well, if plain javascript works you, can use plain javascript well.
if add ids dom elements, use dojo/on
, dojo/dom
modules, example:
require(["dojo/dom", "dojo/on", "dojo/domready!"], function(dom, on) { var myselect = dom.byid("myselect"); on(myselect, "change", function() { dom.byid("mylabel").innerhtml = myselect.value; }); });
otherwise, use jquery-a-like syntax using nodelists , dojo/query
:
require(["dojo/query", "dojo/nodelist-manipulate", "dojo/domready!"], function(query) { query("select").on("change", function() { query("label").innerhtml(this.value); }); });
if you're using dijit/form/filteringselect
in stead of normal <select>
box, have use dijit/registry
obtain widget instance , use on()
method on add event handlers, example:
require(["dojo/dom", "dojo/ready", "dijit/registry"], function(dom, ready, registry) { ready(function() { registry.byid("myselect").on("change", function() { dom.byid("lbl").innerhtml = this.get("displayedvalue"); }); }); });
if you're trying set value of textbox in stead of using label, have set value
property of dom node in stead of innerhtml
property.
Comments
Post a Comment