views:

286

answers:

2

I included one file (containing a form) two times in php file.I want to submit one form with onclick function. both forms are same. i wrote onclick function document.formname.submit();

I want to do somthing like this document.this.form.submit(); please give some solution.

+1  A: 

your forms should be something like this

   <form name="form1">
   ......
   <input type="submit" value="this submits form1">
   </form>


   <form name="form2">
   ......
   <input type="submit" value="this submits form2">
   </form>

Not like this:

   <form name="form1">
   ......
   <input type="submit" value="this submits form1">

   <form name="form2">
   ......
   <input type="submit" value="this submits form2">
   </form>
   </form>

You can not put one form into another.

Sarfraz
<form name="form1"> ...... <a href="#" onclick="document.form1.submit();">submit</a> </form> <form name="form1"> ...... <a href="#" onclick="document.form1.submit();">submit</a> </form>both forms are same i want something like this:<a href="#" onclick="document.this.submit();">submit</a>
uwillneverknow
+1  A: 

with a button inside the form, you can do

$('form input[type="button"]').click(function ()
{
    $(this.form).submit();
})

edit

ok, so per OP's comment, it's anchors, not inputs:

$('form a').click(function ()
{
    $(this).closest('form').submit();
})
just somebody
+1. Though type="submit" would probably be better.
Matt
that'd need `return false` to prevent double-submission, and wouldn't need the handler in the first place.
just somebody
I am using a link to submit a form not submit button.<form name="form1"> ...... <a href="#" onclick="document.form1.submit();">submit</a> </form> <form name="form1"> ...... <a href="#" onclick="document.form1.submit();">submit</a> </form> both forms are same i want something like this: <a href="#" onclick="document.this.submit();">submit</a>
uwillneverknow
@uwillneverknow: that's not wise. semantic web? <a>'s are not meant for that, *and* you're inflicting unnecessary work, as you can see now. that said, see edited answer.
just somebody