SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Referencing Form Elements Named as an Array

    Hey everyone!

    I have a script that loops through (with PHP) and lists items that have fields attatched to each of them. Basically 2 input fields per item. When you enter a number in one field, the other field gets updated.
    so basically the fields are named something like this.

    amount[23] - total[23]
    amount[24] - total[24]
    amount[25] - total[25]

    the array key is just the item's unique ID .

    Problem is, I am not sure how to access the arrays with javascript. The array format of the variable name is making things difficult for me.

    Basically I have been trying to reference them like this... Although I know it wont work...


    Code:
    document.form1.total[x].value=formatCurrency(document.form1.amount[x].value*25);
    This is in a function. x is passed to the function and is the related itemID for the field that is being operated on.

    I am not much of a client side programmer. My understanding in javascript is when you use [] in the matter that I have, it is usually selecting a item that is under it. Like if I wanted to do the samething I just did, but shorter, it would be document[form1].total.value
    Is that right?

    Anyways, real question is, how can I alter my code to select the input element I want to work with.

  2. #2
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    K, so maybe this is a better question: Is this even possible?


Bookmarks

Posting Permissions

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