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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts

    WHY isn't this working? EASY..object has no properties...passing form name/elementnam

    hey all,

    why am I having a brain fart on this...its easy..what obvious thing am I missing?

    I am passing the "form name & element name" via function call..

    inputValues('carform.textdata','17.00')

    to a function...but when I try to "use" the passed variable, I get errors "blah blah..has no properties.

    function inputValues(boxName, boxValue){
    document[boxName].value=boxValue;
    }

    I've tried everything..
    document(boxName).value=boxValue
    document.boxName.value
    document.[boxName].value
    with periods, without..with brackets, without...
    etc..
    etc..

    when I throw an alert..the CORRECT value is in the variable name..when I hard code it..
    document.carform.textdata.value
    it works just fine...

    what is the deal?..is it interpreting the value as a non-string... dont' know..help..
    thanks,
    james

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Not quite everything...

    inputValues(carform.textdata,'17.00')

    inputValues(carform['textdata'],'17.00')

    inputValues(document['carform']['textdata'],'17.00')

    inputValues(document.carform.textdata,'17.00')

    You're trying to fix the wrong end of things (the function - where only eval() - maybe - would help). The document. reference is probably necessary, too. All an alert() will show is a string version of what you pass it; using the typeof operator often helps. In this case: string.

    The dot is part of 'dot syntax'; using string indices (indexes) is a different notation altogether. Mix them carefully.
    Last edited by adios; 07-24-2002 at 11:07 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks for your reply,

    but none of those worked...

    try it out....

    here is the link:

    <form name=carform>
    <input type=text name="datebox" size=15><a href="javascript:inputValues('carform.datebox','17.00');" onmouseover="window.status='some info';return true;" onmouseout="window.status='';return true;">CHANGE</a></form>


    Here is the function:

    function inputValues(boxName, boxValue){
    document.boxName.value=boxValue;
    }



    as you can see, all very very easy...but doen't work..I tried all your solutions and mine...but its not "recognizing the "object"...has no properties...darn...

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    <form name=carform>
    <input type=text name="datebox" size=15><a href="javascript&#58;void inputValues('datebox','17.00');" onmouseover="window.status='some info';return true;" onmouseout="window.status='';return true;">CHANGE</a></form>


    Here is the function:

    function inputValues(boxName, boxValue){
    document.carform[boxName].value=boxValue;
    }

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I DELETED THIS POST cause I found a solution
    Last edited by BrightNail; 07-25-2002 at 09:02 AM.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    YEAH>>>

    I FOUND A SOLUTION..get it out...

    I found that if I put them seperate ....
    inputValues('carform','datebox','17.00');
    IT WORKS!>..but...I can't have "3" values passed...only 2. so, I see that it creates a possibility....

    so,,,,I decided to "split" the first variable into '2' into the function and then USE them...so, this is what i have...

    function inputValues(boxName,boxValue){
    var result=boxName.split(".");
    document[result[0]][result[1]].value=boxValue;
    }


  •  

    Posting Permissions

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