Using parameter in document.__.submit()

Discussion in 'JavaScript' started by dfarrell, Jun 20, 2009.

  1. #1
    Hi. I want to pass a parameter to a js function and then use that parameter as the reference form in a document.__.submit() statement in the function. The coding is below. The js function fires, but the form fails to be submitted by the js. I am probably missing something obvious here, but...? Thanks to anyone who can shed some light on this for me!

    <script language="JavaScript" type="text/javascript">
    function openmydoc(theform)
    {
    document.theform.submit();
    }
    </script>

    <form name="opendoc101" action="document.php" method="POST" id="101" >
    </form>

    <a href="javascript: openmydoc('opendoc101')">Do It</a>
     
    dfarrell, Jun 20, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    haven't tested this but the parameter that you are passing to the document is a string so this should work:
    
    <script language="JavaScript" type="text/javascript">
    function openmydoc(theform)
    {
    document.getElementById(theform).submit();
    }
    </script>
    
    <form name="opendoc101" action="document.php" method="POST" id="101" >
    </form>
    
    <a href="javascript: openmydoc('opendoc101')">Do It</a>
    
    Code (markup):
     
    camjohnson95, Jun 20, 2009 IP
  3. dfarrell

    dfarrell Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That worked. Thanks very much camjohnson95!
     
    dfarrell, Jun 20, 2009 IP