PDA

View Full Version : Submitting a form with a standard href


misterx
12-08-2002, 11:41 PM
Hello,
I'm wondering if there is some kind of event handler or property or something that will let me submit a form without actually making <input type="submit"> or <input type="image" src="...">.

So like....I could have an <img> tag in place of my submit button, and then I could say onClick="some_command_that_will_submit_a_form". Thanks in advance for your help.

whammy
12-09-2002, 12:23 AM
<a href="javascript:document.FORMNAME.submit()">Link here</a>

requestcode
12-09-2002, 03:19 AM
That will work if your form is not using "mailto:email@addr.com" in the action field of the FORM tag.

whammy
12-09-2002, 03:20 AM
Haven't tested it... but it should work in that case too, shouldn't it? Whatever the action is of the form should be performed upon form submission?

Edit:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>asdf</title>
</head>
<body>
<form id="hooray" action="mailto:bill@microsoft.com" method="post" enctype="text/plain">
</form>
<a href="javascript:document.forms['hooray'].submit()">Link here</a>
</body>
</html>

misterx
12-09-2002, 08:09 PM
Yeah that trick worked fine. I just couldn't remember if there was a method for that or not. The form itself is mostly PHP driven so there isn't any mailto stuff to worry about. You can see the results here: http://www.maniacalmonkey.com/php/contact
login/pass = tester/tester

Thanks again for the help.