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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    submitting a form when a link is clicked

    Hi,
    How using Javascript can a form be submitted upon a link being clicked? Or, is this even possble? I hope that is a good enopugh explanation - i couldnt think how else to say it!!

    Cheers.

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <html>
    	<head>
    		<title>Submit form on link click</title>
    	</head>
    	<body>
    		<form action="" method="get" id="fm">
    			<input type="text" name="sub" value="mit">
    			<a href="" onclick="document.getElementById('fm').submit();return false;">Submit</a>
    		</form>
    	</body>
    </html>
    It is always better to use proper form widgets (like a proper submit button), it's what they're there for, and people know their functionality already (so it's a usability thing, and more accessible to other devices).

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hemebond
    Code:
    <html>
    	<head>
    		<title>Submit form on link click</title>
    	</head>
    	<body>
    		<form action="" method="get" id="fm">
    			<input type="text" name="sub" value="mit">
    			<a href="" onclick="document.getElementById('fm').submit();return false;">Submit</a>
    		</form>
    	</body>
    </html>
    It is always better to use proper form widgets (like a proper submit button), it's what they're there for, and people know their functionality already (so it's a usability thing, and more accessible to other devices).
    Thanks, does the action have to be 'get'? also where do i say the page to send it to, is it in action='' or <a href='' or both?

    The reason I have this sort of functinalityis coz i have an ebay style 'matching categories' on my search results page and as far as i could think this was the only way i could successfully do it.

    Thanks again.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well the method doesn't have to be GET, it could be POST.

    And the page you want to submit to would be the specified in the ACTION attribute of the FORM tag.

    Happy coding!
    Sadiq.


  •  

    Posting Permissions

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