Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with "dot notation"

    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
    }

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    document.all is for Internet Explorer 4. For version 5+ browsers you should be using document.getElementById
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •