Forums

ASP

This topic is locked

Mixing ASP and JavaScript on page?

Posted 26 Feb 2007 18:32:41
1
has voted
26 Feb 2007 18:32:41 Dennis Buttery posted:
Hi all,

I'm new here so this may already have been asked & answered ...

1) I have a HTML form on a page to collect user info.
2) I have a JavaScript function that validates the form and returns true/false on validation result.
3) I have some ASP code that formats a mail message based on the form fields and e-mails it ...

Problem: #2 and #3 do not work together!

I can get one or the other to work but not both.

I have tried:
a) Using the standard Submit button and call the validation from 'onClick'
b) Moving the ASP code to a separate .asp page and calling it in the Form 'action'
c) Every other idea I could come up with...

What is the trick here???

Thanks in advance for any help you can provide!

-Dennis

Replies

Replied 27 Feb 2007 13:19:26
27 Feb 2007 13:19:26 praveena kante replied:
Hi,

the combinations of 2 and 3 are possible
check out this sample code:
html------

<html>
<head>
<script language="JavaScript">
function CheckForm(form)
{
var strE = form.Employee_FullName.value;
if (strE == "" || strE== null)
{
alert("Employee name is a required field.";
form.Employee_FullName.focus();
form.Employee_FullName.select();
return false;
}
return true;
}
</script>
</head>
<body>
<p>
<form action='mailto.asp' method="post" onSubmit="return CheckForm(this)" ID="Form1">
<table cellSpacing="0" cellPadding="2" width="500" border="0">
<tr>
<td width="150" bgcolor="#ffffcc" class="smallfont">Employee Name:<font color="red">*</font>
</td>
<td width="350" bgcolor="#ffffcc">
<input type="text" name="Employee_FullName" size="30">
</td>
</tr>
</table>
</form>
</p>
</body>
</html>


asp --------------------

send mail accessing the forrm varibales using request.form("Employee_FullName" etc

let me know if any issues


praveena
Replied 28 Feb 2007 16:02:21
28 Feb 2007 16:02:21 Dennis Buttery replied:
Got it!

Thanks!
Replied 05 Mar 2007 13:47:52
05 Mar 2007 13:47:52 Lee Diggins replied:
Hi Praveena

Just as a tip.

If I turn off javascript in my browser your Checkform() function will not run any validation on the submitted form. Make sure you also validate the data at the server end before you call your serve based mail component, otherwise it'll throw an error.

Remember - ALWAYS VALIDATE DATA AT THE SERVER! <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic