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 8 of 8
  1. #1
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts

    document.getElementById(formID).submit() will work or not

    i have the form id and i want to submit the form

    Code:
    document.getElementById(formID).submit();
    Is this the correct way or not
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Yes, I believe so. Try testing it, or google it. First link from google search: http://www.javascript-coder.com/java...m-submit.phtml

  • #3
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    Its not working ,

    I think in that link was using form name and i want to use formID . thats why its not working
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #4
    Regular Coder ghostz00's Avatar
    Join Date
    Aug 2006
    Posts
    128
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Make sure that the formid is in quotes.

    Code:
    document.getElementById("formID").submit();
    Greg

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Sorry I couldn't get right back to you; had to rush out and do something as soon as I sat down to answer.

    I think in that link was using form name and i want to use formID . thats why its not working
    That's not it. They were using a different (and more traditional) way of traversing the DOM, but it still selects the same element. It's like the different between going somewhere in a helicopter (getElementByID) and driving there on surface streets (document.formname).

    Try
    Code:
    var myform=document.getElementById(formID);
    myform.submit();
    One last thing to note is that you are specifying the id of your form correctly; sometimes I get confused and accidentally specify it as the name.

    BTW, is that all the code you have so far? If there's a specific situation you're using it in, there could be other elements effecting it.

  • #6
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    I am using one form with multi buttons , i am using code below



    Code:
    function submitForm2(formID , action)
    
    {
    
    document.getElementById(formID).action = action;
    
    document.getElementById(formID).submit();
    
    }

    <
    Code:
    form id = 'form_1' action="" method=post>
    
    <input class="left" type="button" name="submit" value="Show" 
        onClick="submitForm2('form_1','test.php')"> 
    
    <input class="left" type="button" name="submit" value="Show" 
        onClick="submitForm2('form_1','test2.php')">
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #7
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can not have the buttons named submit and use submit(). The buttons override the method. Rename the buttons to something else and it will work.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Make sure you have no element with the name or id = "submit". IE woun't like that, as it will be confused between what it considers an object referenced by the name/id submit and the method submit()
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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