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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts

    <RESOLVED>Why can't I submit?

    <RESOLVED>

    Hey guys,

    I'm trying to use javascript to submit a form. I was wondering whether this was possible.

    Code:
    <html>
    <head>
    <script language='JavaScript'>
    function submitURL(url) {
      document.mForm.url.value = url;
      document.mForm.submit();
    }</script>
    
    <form action="test12.php" method="post" name = "mForm" id = 'mIDForm'>
    URL: <input type="text" name="url" />
    </form> <P>
    
    <A HREF=""
    onClick="submitURL('http://www.google.com')";>Google</A>
    
    </body>
    </html>
    Clicking on the link puts the correct URL in the input field, but then the page refreshes and nothing gets sent to test12.php.

    Anyone have any clue?

    Thanks much.

    <RESOLVED>

    Thanks a lot
    Last edited by Pembar; 06-24-2009 at 09:51 PM. Reason: Resolved

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    The page "refreshes" because of the anchor tag with the empty href - that means go back to self. If you don't want to follow that link, try using a "return false;" along with the function call.

    Not sure if that will work for anchors, but that's how to break the submit for a button.
    Are you a Help Vampire?


  •  

    Posting Permissions

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