0

.I have this code1:

<form method="GET" action="picture.php">

.usually the value of i1 will be sent if i use this code2:

<input type="submit">

.Is there a way to trigger the "submit" function by using a jquery instead of code2? help pls!

3
  • Please, add the tags "jquery" and "javascript" next time. Thanks. Commented Mar 2, 2011 at 15:47
  • Alright.. i'm sorry for that. Commented Mar 2, 2011 at 15:57
  • Please include the full HTML of the form you are using. Commented Mar 2, 2011 at 19:31

3 Answers 3

2
<form method="GET" action="picture.php" id="picture-form">

... followed by the following call in javascript, wherever it might be required ...

$('form#picture-form').submit();

Note that an ID has been added to the form for an accurate jQuery reference. just doing $('form').submit(); could be very evil.

Fully fledged example follows.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<form method="GET" action="picture.php" id="picture-form">
    <a href="javascript:void(0);" onclick="$('form#picture-form').submit();">Submit me!</a>
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

+1.. btw i wouln't use "followed by", he might actually get it literally.
.I used your code $('form#picture-form').submit(); but still when i click the link is does not forward the code to the next php page.
It definitely can work. I've knocked up a really simple example above. If you can post what you've got, maybe we can spot why it isn't working.
0

take a look at this link : http://api.jquery.com/submit/ - Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.

Comments

0

There's even no need for jQuery, you can do it in vanilla JavaScript:

<form method="GET" action="picture.php" id="picture-form">
 <a href="#" onclick="document.getElementById("picture-form").submit()>Click me!</a>
... 
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.