document.forms[variable].submit var=variable how to pass a variable

Discussion in 'JavaScript' started by xbat, Dec 5, 2020.

  1. #1
    document.forms[variable].submit var=variable how to pass a variable

    So for example if I run document.forms[variable].submit and change the word varaible to a static item then it gets the id from the form.. What I am trying to do use var =x or var=variable

    Whats in the var is actually the id it will be submitting in javascript
     
    Solved! View solution.
    xbat, Dec 5, 2020 IP
  2. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #2
    variable is the key of the forms-Array. But you want to use and object instead of the key value?
     
    iago111, Dec 6, 2020 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    there is multiple forms on one page and I am using the <form id="XXX" then XXX is used on selecting which form. if I manually type in the XXX document.forms["XXX"].submit it works like a charm however if try to dynamic do it then it doesn't work. I have tried var a=xxx; document.forms.a.submit document.forms.(a).submit document.forms.[a].submit and a bunch more I am not sure of the proper dynamic way to put in it.

    I have tried to google and look at other forums etc.. no such luck I am not sure of the proper way.
     
    xbat, Dec 6, 2020 IP
  4. #4
    forms["XXX"] is an object and cannot be replaced by a value, the property a of forms.a is the name value of the specific form. So you can return the forms object like this:
    const formA = document.forms.a, and then apply submit with: formA.submit.
     
    iago111, Dec 6, 2020 IP
  5. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #5
    I understand its a object ;) haha thank you thats what I was looking >> const formA = document.forms.a, and then apply submit with: formA.submit.

    I did just end up rebuilding most of the form today though it works. But now I know how to do it thanks again
     
    xbat, Dec 6, 2020 IP