Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

anchor tag to submit a form

How do I get an anchor tag to submit a form?

this is what I have now....
                <input type="image" name="update" src="/images/go_button.jpg"
                    width="59" height="30">

instead I want this to submit the form...                    
                        <a href="/find.asp">
                            <img src="/template/images/Arrow2.png" border="0" />&nbsp;SEARCH</a>

How doI do that? thanks!
Avatar of Ashish Patel
Ashish Patel
Flag of India image

<a href="javascript:document.forms[0].action='find.asp';document.forms[0].submit();">
                            <img src="/template/images/Arrow2.png" border="0" />&nbsp;SEARCH</a>
Avatar of almilyo
almilyo

make sure you have a name in the form tag, so it looks something like

<form name="theform" >

And then write your link as

<a href="javascript:document.myform.submit();"><img src="/template/images/Arrow2.png" border="0" />&nbsp;SEARCH</a>
sorry, that should have been

<a href="javascript:document.theform.submit();">

in my example.
Avatar of Starr Duskk

ASKER

I must be doing something wrong. Here is my form:

<form name="searchForm" autocomplete="off" method="get" action="/find.asp">

                        <a href="javascript:document.searchForm.submit();">
                        <span>
                            <img src="/template/images/Arrow2.png" border="0" />&nbsp;SEARCH</span></a>

It submits to a page that doesn't exist:
/templatedefault.asp?

my path to this page is:
/template/default.asp
<form name="searchForm" autocomplete="off" method="post" action="/find.asp">
                        <a href="javascript:document.searchForm.action='/find.asp';document.searchForm.submit();">
                        <span>
                            <img src="/template/images/Arrow2.png" border="0" />&nbsp;SEARCH</span></a>
I just did that too....
<a href="javascript:document.searchForm.action='/find.asp';document.searchForm.submit();">

it does the same error.
oh wait. I see you are doing a "post" method and my code has a "get" method.

(existing code, trust me, I'd never do a "get"....)

Is that the problem?
No, switching to "post" doesn't do it either.
try re-changing it from post to get again
ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial