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 7 of 7
  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    Use javascript to submit from but in php loop

    I want to submit form using javascript but as I see javascript doesn't work in php loop. I use this code:

    Code:
    <form name="theForm">
    <input type=text name="formInput">
    <a href="javascript:document.theForm.submit();">Submit</a>
    </form>
    and it works fine in ordinary page, but stops working in php loop! I need to use link, not button to submit form.

    Can anyone please help?

    Thanks in advance

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    What do you mean by
    in PHP loop
    ?
    Software and cathedrals are much the same - first we build them, then we pray.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    if the form is in a loop, ie: so you have several forms,
    just add the record id to the form name, like: theForm_1 and the same for the javascript reference to the form.

    Code:
    <form name="theForm_1">
    <input type=text name="formInput">
    <a href="javascript:document.theForm_1.submit();">Submit</a>
    </form>

  • #4
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    try putting this instead:

    Code:
    <a href="#" onclick="document.theForm.submit();">Submit</a>
    Software and cathedrals are much the same - first we build them, then we pray.

  • #5
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    What do you mean by
    The whole code is rather complicated to post, it's a wordpress comment loop. I want to add above code after every comment.

    Code:
    <a href="#" onclick="document.theForm.submit();">Submit</a>
    This code doesn't work. It displays the submit button but when I click it nothing happens.
    Last edited by levani; 09-10-2009 at 05:20 PM.

  • #6
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts
    Try:

    Code:
    <a href="#" onclick="document.forms[0].submit()">Submit</a>
    or:
    Code:
    <a href="#" onclick="document.forms['formName'].submit()">Submit</a>

    It is very poor practice, though, to use JavaScript within an HTML element.

    Either way, they are both, to use a technical term, crap.
    Last edited by 12 Pack Mack; 09-10-2009 at 07:16 PM.

  • #7
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Quote Originally Posted by 12 Pack Mack View Post
    Try:

    Code:
    <a href="#" onclick="document.forms[0].submit()">Submit</a>
    It is very poor practice, though, to use JavaScript within an HTML element.
    This way the link will always load the first form of the document.

    In fact there is a list of forms in the document and in each form there is a link and he needs the link to submit the form in which it exists.
    Software and cathedrals are much the same - first we build them, then we pray.


  •  

    Tags for this Thread

    Posting Permissions

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