...

View Full Version : help with "dot notation"



larsonr
10-21-2005, 03:51 PM
Hi...

I've tried searching on "dot notation" before writing here but after looking at at least 20 items the search found, none seem to be remotely close to my needs.

I am writing a simple script which based on a checkbox being checked, will run, causing some fields on a form to be readonly or not readonly.

My problems is that some fields are easily referenced while a few others have a more complicated naming which contains multiple dots. No javascript errors occur but no action at all is performed on these.

Question: How does one work around this?

The page is a jsp where
textName, textUCN, and tempClient are easily referenced within the form
but
objectDto.tempClientName is the reference of a java object and property
This input tag is the from the compiled source of the page displayed:
<input type="text" name="objectDto.tempClientName">

The function below works except for the lines referencing objectDto.tempClientName

function checkTempDisable() {
if (document.all.tempClient.checked) {
//enable text fields
document.all.textName.setAttribute('readOnly',true);
document.all.textUCN.setAttribute('readOnly',true);

//disable text fields
document.all.objectDto.tempClientName.value="";
document.all.objectDto.tempClientName.setAttribute
('readOnly',false);
document.all.objectDto.tempClientName.focus();
}else{
//enable text fields
document.all.textName.setAttribute('readOnly',false);
document.all.textUCN.setAttribute('readOnly',false);
document.all.clientName.focus();

//disable text fields
document.all.objectDto.tempClientName.value="";
document.all.objectDto.tempClientName.setAttribute
('readOnly',true);
}
return
}

Brandoe85
10-21-2005, 04:01 PM
You could use square bracket notation:
document['MyForm']['my.name'].value

heres a link to glenngv's sig, where theres a link to square bracket notation:
http://www.codingforums.com/member.php?u=42

Pyth007
10-21-2005, 05:58 PM
I also noticed under your "// enable text field" comments, you have the field's readOnly set to true and vice vs. Setting readOnly to true disables that field (not sure if comment or code is in error)

Also, if your problem is that the fields are not receiving focus like you expect and you are using IE, you may have to setTimeout("document.all.objectDto.tempClientName.focus();",100) to allow IE to finish processing the function; IE has a bad habit of not giving an element focus (or be selected) when in the middle of a function...

felgall
10-22-2005, 12:01 AM
document.all is for Internet Explorer 4. For version 5+ browsers you should be using document.getElementById



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum