Login Register

Getting the value of a Textbox

I've been using dojo for a while, but for some reason i cant get the value of a Textbox in my page.I need the value of the box so i can run a search based on that value.I always use dijit.byID to get the widget, but now FF2 error console is telling me that "dijit.byID is not a function".Before, i used
var x=dijit.byId("Element") so i could do x.setAttribute("something",1) but now its not working.
Specific code follows

<input type="text" id="param_srch" name="Nctrl_srch" value="04210825" dojoType="dijit.form.TextBox">
<button dojoType="dijit.form.Button"
 onClick='var x=dijit.byID("param_srch");Num_ctrl=x.getDisplayedValue();dijit.byId("mainDisplay").setHref("/alumnos_srch.php?Num_Ctrl="+Num_Ctrl);'
  type='submit' label="Buscar">
</button>

this is the inline version, I've tried it in a function in a separate js file, including it in a tag, also done 'var x=dijit.byID("param_srch").getDisplayedValue", .getValue instead of DisplayedValue, used "Nctrl_srch" instead of "param_srch", "dojo.byID" instead of "dijit.byID"....i dont know what else to try.
Any help is much appreciated, thanks!

FF is telling the truth. The

FF is telling the truth. The function is dijit.byId() not dijit.byID(). JavaScript is case sensitive.

Thanks!

The levels of stupid i feel cannot be measured....anyhow, Thanks!

Cannot get the 'value' of a digit.form.Textarea in any way.

I am trying to implement a function to advise the user of number of characters in a textarea.
Here is my widget definition:

<textarea style="width: 300px;"
dojoType="dijit.form.Textarea"
id="descTxt" name="descTxt" >
</textarea>

All the right classes are loaded and the textarea behaves as it should.
 

dojo.require("dojo.parser");
                                dojo.require("dijit.form.Form");
                                 dojo.require("dijit.form.Button");
                                 dojo.require("dijit.form.TextBox")
                                dojo.require("dijit.form.CheckBox");
                                dojo.require("dijit.form.DateTextBox");
                                //dojo.require("dijit.form.CurrencyTextBox");
                                dojo.require("dijit.TitlePane");
                                dojo.require("dijit.form.TextArea");
                                dojo.require("dijit.Tooltip")

I managed to attach an onkeyup event to the text area and get it to fire:
dojo.addOnLoad(function(){var txtarea = dojo.byId("descTxt"); dojo.connect(txtarea,"onkeyup",textCounter ) } )
Here is the textCounter function, which does fire:

function textCounter()
{
        var ctrl = dojo.byId("descTxt")
        var cntfld = dojo.byId("cntfld")
        alert(ctrl.id)
        var val = ctrl.getValue() //**********************
        alert(val)
                if (val == undefined ) { return }
                if (val.length > 255) // if too long...trim it!
                {
                        val = val.substring(0, 255);
                }
                else
                {
                        cntfld.value = 255- val.length;
                }
}

The function fires, the alert in line 3 gets the correct id, but line 4 ( the one with the commented asterisks ) is the problem.
I have tried getValue() and getDisplayedValue; both raise errors saying that the functions do not exist.
I tried using ctrl.value: That did not raise an exception but val ( ctrl.value) is ALWAYS undefined!

The docs define both the value property and the getValue() method

Can anyone tell me what the problem is? Have I left some kind of a 'required' out?

Interestingly enough, I found the answer to this elsewhere...

Someone was have the same problem with a textbox. An answer was given, but it still did not work until I took an extra step. I posted my working example there and I will post it here as well:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<!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>