bex1985 wrote:
> I have made a questionnaire on frontpage and want to send it by email
> as an attachment. The problem I have is that when i test it and press
> 'submit' nothing happens - it just opens another webpage and no
> results are sent. I have gone into the form properties and typed in
> an email address but i dont why its not working!
> Please help!
> Or could you tell me an alternative way of receiving the results
> without having a submit button?
Try thtis code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<!-- formtest.html -->
<head>
<title>Form Test</title>
<!-- Internal JS -->
<script type="text/javascript">
function checkEmailAddress(field)
{
// the following expression in () after 'match' must be all on one line...
if
(field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))
return true
else
{ alert('Please enter a valid e-mail address.')
field.focus()
field.select()
return false }
}
// --------------------
function testform()
{
with (document.form1)
{
if (!checkEmailAddress(Email))
return
// Other tests in here
}
}
// --------------------
function sendform()
{
with (document.form1)
{
var body = ''
var i = elements.length , j = 0
while (i-- > 2) // drop last two elements
{
var text = elements[j].value
var tname = elements[j].name
body += tname +': ' + text + '%0d%0a' // line break after
each field }
j += 1
} // end while
}
window.location = "mailto:" + "me" + "@" + "mysite" + ".com.au"
+ "?subject=Response%20from%20Form"
+ "&body=" + body
}
// --------------------
</script>
</head>
<!-- ================================================ -->
<body>
<noscript>
This site requires Javascript enabled<br />
</noscript>
<div id="maindiv" align="center">
<div style="border:1px solid #999999; width:60%;
background-color:#F2F4FA;">
<form name="form1" action="">
<div style="background-color:#DBE0F5; padding:3px; font:75% arial;">
<b>Title</b>
</div>
<div style="padding:10px; font:75% Arial; text-align:left;">
<p>
Some intro,<br />
.............
</p>
<p>
Name:<br/>
<input type="text" id="Name" value="Insert name" size="40"
onfocus="if (this.value=='Insert name'){this.value='';};return
false;"
onblur="if (this.value==''){this.value='Insert name';return
false;}"/><br/>
Email:<br/>
<input type="text" id="Email" value="Insert e-mail address" size="40"
onfocus="if (this.value=='Insert e-mail
address'){this.value='';};return false;"
onblur="if (this.value==''){this.value='Insert e-mail
address';return false;}"/><br/>
Enter Comment:<br/>
<textarea id="Comment" rows="10" cols="100"
style="font:100% Arial;">Enter your comment in
here</textarea><br />
<!-- Enter other fields in here -->
</p>
</div>
<!-- Leave these two fields as last -->
<div align="center" style="background-color:#DBE0F5; padding:3px;
font:12px arial;">
<input type="button" id="submit" value=" Send "
onmouseover="testform()" onclick="sendform()" />
<input type="reset" id="reset" value=" Clear "/>
</div>
</form>
</div>
</div> <!-- end id="maindiv" -->
</body>
</html>
It is cut from another form which works, but I haven't tested it.
The key points are action="" in the form definition and the Submit button
with onmouseover= and onclick=
It is possible that the type of this button does not have to be "submit",
because the onclick= should handle it.
--
Cheers,
Trevor L.
Website:
http://tandcl.homemail.com.au