Enjoy an ad free experience by logging in. Not a member yet?
Register .
09-10-2009, 03:53 PM
PM User |
#1
Regular Coder
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
09-10-2009, 04:00 PM
PM User |
#2
Senior Coder
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
__________________
Software and cathedrals are much the same - first we build them, then we pray.
09-10-2009, 04:04 PM
PM User |
#3
Senior Coder
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
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>
09-10-2009, 04:12 PM
PM User |
#4
Senior Coder
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.
09-10-2009, 04:13 PM
PM User |
#5
Regular Coder
Join Date: Mar 2009
Location: Georgia
Posts: 183
Thanks: 29
Thanked 1 Time in 1 Post
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 04:20 PM ..
09-10-2009, 06:02 PM
PM User |
#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 06:16 PM ..
09-10-2009, 06:06 PM
PM User |
#7
Senior Coder
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
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.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 05:53 AM .
Advertisement
Log in to turn off these ads.