Javascript
I'm running in J2EE world (JSP/JSTL/Servlets the like), and am having problems pulling a field back from my page, or, I'm having problems actually locking the element.
If I use the disabled property, a null (or no object) is returned back to the backend (servlet). However the front end acts like I want it too. If I use the readonly property, I can never seem to enter text in even if using javascript to change the property to false. Suggestions?
Here's one of the html input elements:
<INPUT type="text" style="width:40px" class="inputSmall inputPercentage" id="S_1_3" name="S_1_3" value="5 readonly="true" />
Here's version 1 of the javascript:
function onCall() {
for(cnt=0; cnt<numElems; cnt++){
if(chkBox.checked) {
disableElem(document.getElementById( "S_" + cntRow + "_" + cntShip));
} else {
enableElem(document.getElementBy Id("S_" + cntRow + "_" + cntShip));
}
}
function disableElem(elem) {
if(elem != undefined) {
elem.value = 0;
elem.className = "inputSmall inputPercentage formfield-disabled";
elem.readonly = true;
}
}
function enableElem(elem) {
if(elem != undefined) {
elem.readonly = false;
elem.className = "inputSmall inputPercentage";
}
}
x-posted to
java_dev and
javascript
Update and Solution: To properly reference the readonly attribute in javascript, captilization matters. I'm now referencing elem.readOnly and it works beautifully.
If I use the disabled property, a null (or no object) is returned back to the backend (servlet). However the front end acts like I want it too. If I use the readonly property, I can never seem to enter text in even if using javascript to change the property to false. Suggestions?
Here's one of the html input elements:
<INPUT type="text" style="width:40px" class="inputSmall inputPercentage" id="S_1_3" name="S_1_3" value="5 readonly="true" />
Here's version 1 of the javascript:
function onCall() {
for(cnt=0; cnt<numElems; cnt++){
if(chkBox.checked) {
disableElem(document.getElementById(
} else {
enableElem(document.getElementBy
}
}
function disableElem(elem) {
if(elem != undefined) {
elem.value = 0;
elem.className = "inputSmall inputPercentage formfield-disabled";
elem.readonly = true;
}
}
function enableElem(elem) {
if(elem != undefined) {
elem.readonly = false;
elem.className = "inputSmall inputPercentage";
}
}
x-posted to
java_dev and
javascriptUpdate and Solution: To properly reference the readonly attribute in javascript, captilization matters. I'm now referencing elem.readOnly and it works beautifully.