Login Register

How do I simply get the value of a textarea? getValue() not working?

I have been searching for awhile for the solution to this seemingly simple question.

How do I get the value of a digit textarea?

Bla Blah Blah


...

myNotes = dojo.byId("myNotes").getValue();

This gives the console error in Firebug, "dojo.byId("myNotes").getValue is not a function". Is this not how it is supposed to work?

console.log(dojo.byId("myNotes")) gives "" in the firebug console.

Try this...

try dijit.byId("myNotes") - since it's an actual widget. dojo.byId returns the reference to the DOM node (which won't have a getValue function) - dijit.byId will return the reference to the widget that the DOM node belongs to (which *does* have a getValue function)

When I first tried this...

I got a dijit is undefined error.

You have to add this:
<script type="text/javascript" src="http://localhost/dojo/dijit/dijit.js"
djConfig="parseOnLoad: true"></script>

This functionality needs to be better documented. I spent hours on this and searched and searched.

That did the trick, and

That did the trick, and helps explain other things as well... A million thank-yous toonetown :)

Howto get the content of an AccordionPane?

I like to get the value of the Title and maybe the content of the actual opened Pane in a accordioncontainer. I have created it like this:

accordion = new dijit.layout.AccordionContainer({id:"acco", widgetId:"acco"}, accorddiv);
for (var i = 0; i < daten.length; i++) {
	var comment = daten[i];
 	var pane = new dijit.layout.AccordionPane({title:comment.datum+" von "+comment.uname})
	accordion.addChild(pane);
	pane.setContent(comment.comment);
}
	
accordion.startup();
accordion.layout();

Is there also something easy like the solution before?

How to attach a character counter to textbox:

I spent hours on this problem, so I though I would post it here.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Text Area Character Counter</title>
<style type="text/css">
@import "http://localhost/dojo/dijit/themes/tundra/tundra.css";
@import "http://localhost/dojo/dojo/resources/dojo.css";
@import "general.css";
@import "form.css";
</style>
<style type="text/css">
</style>
<script type="text/javascript" src="http://localhost/dojo/dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript" src="http://localhost/dojo/dijit/dijit.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.Form");
dojo.require("dijit.form.Textarea");
</script>
<script type="text/javascript" >
function textCounter()
{
maxlimit = 255
var ctrl = dijit.byId("descTxt")
var cntfld = dojo.byId("cntfld")
//alert(ctrl.id)
var val = ctrl.getValue()
//alert(val)
if (val == undefined ) { return }
if (val.length > maxlimit) // if too long...trim it!
{
val = val.substring(0, maxlimit);
ctrl.setValue(val)
}
else
{
cntfld.innerHTML = val.length;
}
}

</script>
</head>
<body class="tundra">
<form type="digit.form.Form" id="entityform" method="post" action="">
<h2>Text Area Character Counter in Dojo and Dijit</h2>
<div>
<span class="label" for="DescTxt">Description</span>
<textarea style="width: 300px;"
dojoType="dijit.form.Textarea"
id="descTxt" name="descTxt"
</textarea>
<!-- This is the counter field -->
<span name="cntfld" id="cntfld" style="border: dotted 1px navy" > </span>
</div>
`</form>
</body>
<script>
dojo.addOnLoad(function(){var txtarea = dojo.byId("descTxt"); dojo.connect(txtarea,"onkeyup",textCounter ) } )
</script>
</html>