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
    Oct 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using arrays with formName.elements[].value

    I am trying (without success) to insert an array into... formObj.elements[ARRAY GOES HERE].value

    - I have a form with multiple arrays that are passed to functions
    - Function description

    function calculate_row_total(formObj,x)
    {
    parseFloat(formObj.elements['q_index'][x].value);

    etc...

    }

    - the variable 'q_index' is an array used to name multiple form fields.

    Any ideas? Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And what does x represent? The index of the array to use?

    function calculate_row_total(formObj,x)
    {
    parseFloat(formObj.elements[q_index[x]].value);
    }
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply.

    Yes. The variable x represents the index of the array, defined in the form.

    I received the following error when removing the single quotes from the 'parseFloat(formObj.elements[q_index][x].value);'

    ERROR : q_index is undefined.

    Here is my function:

    ----------------------------------------
    function calculate_row_total(formObj,x)
    {
    var quantity = parseFloat(formObj.elements[q_item_row[x]].value);
    var price = parseFloat(formObj.elements[unit_price_row[x]].value);
    var total = quantity * price;
    formObj.elements[total_row[x]].value = total;
    }
    -----------------------------------------------
    Last edited by tampa03; 10-13-2003 at 02:04 PM.

  • #4
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've used similar notation with succes. The following line works without problems:

    formObj.elements['total_all'].value = rows_total;

    The errors appear when I attempt to insert an array inside elements[ARRAY HERE].

    Perhaps the problem is related to concatenation? Any suggestions?

    Thanks.
    Last edited by tampa03; 10-13-2003 at 02:09 PM.


  •  

    Posting Permissions

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