Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2009, 03:53 PM   PM User | #1
levani
Regular Coder

 
levani's Avatar
 
Join Date: Mar 2009
Location: Georgia
Posts: 183
Thanks: 29
Thanked 1 Time in 1 Post
levani is an unknown quantity at this point
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
levani is offline   Reply With Quote
Old 09-10-2009, 04:00 PM   PM User | #2
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
What do you mean by
Quote:
in PHP loop
?
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 09-10-2009, 04:04 PM   PM User | #3
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
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>
angst is offline   Reply With Quote
Old 09-10-2009, 04:12 PM   PM User | #4
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
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.
ckeyrouz is offline   Reply With Quote
Old 09-10-2009, 04:13 PM   PM User | #5
levani
Regular Coder

 
levani's Avatar
 
Join Date: Mar 2009
Location: Georgia
Posts: 183
Thanks: 29
Thanked 1 Time in 1 Post
levani is an unknown quantity at this point
Quote:
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 04:20 PM..
levani is offline   Reply With Quote
Old 09-10-2009, 06:02 PM   PM User | #6
12 Pack Mack
Banned

 
Join Date: Mar 2009
Posts: 248
Thanks: 3
Thanked 68 Times in 66 Posts
12 Pack Mack is an unknown quantity at this point
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..
12 Pack Mack is offline   Reply With Quote
Old 09-10-2009, 06:06 PM   PM User | #7
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
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.
ckeyrouz is offline   Reply With Quote
Reply

Bookmarks

Tags
form, javascript, link, submit

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:53 AM.


Advertisement
Log in to turn off these ads.