Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function
. There is hidden fields that hold all student pair that as <input type="hidden" id="_hidden_studentname_{somestudentid}" value="aStudentName">
, here {somestudentid} only indicate it as student id variable. The purpose of this is try to get a student name by student id.
dojo.connect(dijit.byId('_studentId_id'), 'onChange', function (val) {
var studentId=dijit.byId("_studentId_id").attr("value"); // line 1
var id="_hidden_studentname_"+studentId;
var studentName=dojo.byId(id).attr("value"); // line 3
dojo.byId("_student_text").attr("value", studentName);
});
So dojo doesn't allow variable put in dojo.byId()
? I am pretty sure the <input type="hidden">
with that id does exist....
Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function
. There is hidden fields that hold all student pair that as <input type="hidden" id="_hidden_studentname_{somestudentid}" value="aStudentName">
, here {somestudentid} only indicate it as student id variable. The purpose of this is try to get a student name by student id.
dojo.connect(dijit.byId('_studentId_id'), 'onChange', function (val) {
var studentId=dijit.byId("_studentId_id").attr("value"); // line 1
var id="_hidden_studentname_"+studentId;
var studentName=dojo.byId(id).attr("value"); // line 3
dojo.byId("_student_text").attr("value", studentName);
});
So dojo doesn't allow variable put in dojo.byId()
? I am pretty sure the <input type="hidden">
with that id does exist....
1 Answer
Reset to default 6Note how you were using dijit.byId
in Line 1, but using dojo.byId
in line 3. The former returns a widget (which has an attr
function), wheras dojo.byId
returns a DOM element, which does not have an attr
method.
DOM elements can manipulate attributes directly, so you can update the code to use something.value = 'some other value';
.
dojo.connect(dijit.byId('_studentId_id'), 'onChange', function (val) {
var studentId=dijit.byId("_studentId_id").attr("value"); // line 1
var id="_hidden_studentname_"+studentId;
var studentName=dojo.byId(id).value; // line 3
dojo.byId("_student_text").value =studentName;
});