Is there a way to submit a form, using a text link, instead of a submit button?
Thanks!
| SitePoint Sponsor |

Is there a way to submit a form, using a text link, instead of a submit button?
Thanks!





Hi,
Yes, you can use Javascript to accomplish that. However, a solution like that would only work for those who have Javascript enabled. Those who have disabled it will (probably) not be able to use the form correctly.
HTML Code:<script type="text/javascript"> function submitForm(sFormId) { if( document.forms[sFormId] ) document.forms[sFormId].submit(); } </script>HTML Code:<form id="foo" action="quicktest.html" method="get"> <input type="hidden" name="foo" value="bar" /> <a href="#" onclick="submitForm('foo')">submit</a> </form>
ERIK RIKLUND :: Yes, I've been gone quite a while.
I guess depending on what you are doing you can get the same effect. Our site has a search button on search page which is a form send. A few months ago visiting some dynamic url would give the same result. But you if you are adding values to form before submitting, link won't work. I am not an expert but I think I gave a correct answer.


As lilleman said, you can do it with JavaScript, but that raises accessibility issues.
An alternative way might be to use an <input type="submit"> element, and style it to look like an ordinary link using CSS. You may run into trouble in IE if you want to use the :hover pseudo-class, but that could be resolved with JavaScript onmouseover events. (Not as much of an accessibility issue, since it's only styling, whereas not being able to submit at all is a definite barrier.)
(For IE, you'd probably have to use a class, since it doesn't understand attribute selectors.)Code:/* For CSS2-compliant browsers */ input[type="submit"] { padding:0; border:0; background:transparent; color:#00c; text-decoration:underline; }
The text-decoration doesn't seem to work in Mozilla 1.7.5 or Opera 8, but you could use a bottom border instead.
Birnam wood is come to Dunsinane





Hi,
One way to fix that would be to use the IE7 "patch".Originally Posted by AutisticCuckoo
ERIK RIKLUND :: Yes, I've been gone quite a while.
Bookmarks