By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

javascript form validation which just doesnt work

P: n/a
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.

Here is the code:

///////////////////////////////////////////////
<%

ntlogon = (Request.ServerVariables("LOGON_USER"))
remotehost = (Request.ServerVariables("REMOTE_HOST"))
%>
<body>

<form name="form1" method="post" action="confaddidea.asp"
onSubmit="return validate();">

<font face=Verdana size=2>
<i>Please note all fields marked with * are mandatory.</i>
<i>Click on the <img src="iicon.gif" alt="" width=16px height=16px> icon
for help with each field</i>
<BR><BR>

<table>

<TR>
<TD style="width=265px"> <font face=Verdana size=2>
* First Name :
<BR>
<input name="f_name" size=25 maxlenght=50 class="myform">
<img src="clear.jpg" border=0 width=23 height=20></a><br>
<BR>
* Surname Name :
<BR>
<input name="s_name" size=25 maxlenght=50
class="myform" >
<img src="clear.jpg" border=0 width=23
height=20></a><br>
<BR>

* Email Address:
<BR>

<input name="e_address" size=25 maxlenght=50
class="myform" >
<a href="#" onmouseover="doTooltip(event,0)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br><BR>
* Telephone Number
<BR>
<input name="tel_number" size=25 maxlenght=50
class="myform" >
<a href="#" onmouseover="doTooltip(event,1)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br>
<BR>

* Employee ID :
<BR>
<input name="emp_id" size=25 maxlenght=50
class="myform" >
<a href="#" onmouseover="doTooltip(event,2)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br>
<br>
<BR>
</TD>
<TD style="width=275px" valign="top" align="left">
<font face=Verdana size=2>
Job title :
<BR>
<input name="job_title" style="width=235px"
maxlenght=50 class="myform" >
<a href="#" onmouseover="doTooltip(event,3)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br>
<BR>

</TD>
</TR>
<TD COLSPAN=2>
<font face=Verdana size=2>
* Suggestion Title :
<BR>
<input name="title_suggestion"
style="width=525px" maxlenght=50 class="myform" >
<a href="#" onmouseover="doTooltip(event,7)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br>
<BR>

* Suggestion :
<BR>

<TEXTAREA name="suggestion" rows=15
style="width=525px" size=250 maxlenght=250

class="myform" ></textarea>
<a href="#" onmouseover="doTooltip(event,8)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br>
<BR>

<a href="#" onmouseover="doTooltip(event,9)"
onmouseout="hideTip()">
<img src="iicon.gif" border=0 width=16px
height=16px></a><br>
<BR>

</font>

<input type="hidden" name="ntlogon"
value="<%=ntlogon%>">
<input type="hidden" name="remotehost"
value="<%=remotehost%>">
<input type="submit" value="Submit"
onclick="this.form.submit();this.disabled='true';t his.value='Please
Wait..';">
</td>

</TABLE>
</form>

<div id="tipDiv" style="position:absolute; visibility:hidden;
z-index:100"></div>
<iframe id="tipFrame" style="position:absolute; visibility:hidden;
z-index:90"></iframe>

</body>
</html>
////////////////////////////////////////////
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
x muzuo wrote:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.

Here is the code:

<%
ntlogon = (Request.ServerVariables("LOGON_USER"))
remotehost = (Request.ServerVariables("REMOTE_HOST"))
%>

<body>
<form name="form1" method="post" action="confaddidea.asp"
onSubmit="return validate();">

Where is "valdate()" defined?
And your spelling of "maxlength" is wrong.

[snip]

Mick

Jul 23 '05 #2

P: n/a
On 15 Jan 2005 10:45:23 -0600, in comp.lang.javascript x muzuo
<mu******@yahoo.co.uk> wrote:
| Hi guys,
| I have got a prob of javascript form validation which just doesnt work
| with my ASP code. Can any one help me out please.
|
| Here is the code:
|
| ///////////////////////////////////////////////
| <%
| ntlogon = (Request.ServerVariables("LOGON_USER"))
| remotehost = (Request.ServerVariables("REMOTE_HOST"))
| %>
|
| <body>
| <form name="form1" method="post" action="confaddidea.asp"
| onSubmit="return validate();">


There are no javascript functions defined on/or linked to your page.

[snip]

---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #3

P: n/a


Hi guys,
Thanks for your reply.
sorry about the confusion, here is the validating code.

with many thanks

<<<snipped>>>>

<script type="text/javascript">

//Validating the form

function validate(){
if (document.form1.f_name.value.length < 1) {
alert("Please enter your first name.");
return false;
}
if (document.form1.s_name.value.length < 1) {
alert("Please enter your surname.");
return false;
}
if (document.form1.e_address.value.length < 1) {
alert("Please enter your first name.");
return false;
}
if (document.form1.f_name.value.length < 1) {
alert("Please enter your emailaddress.");
return false;
}
if (document.form1.tel_number.value.length < 1) {
alert("Please enter your telephone number.");
return false;
}
if (document.form1.emp_id.value.length < 1) {
alert("Please enter your employee ID.");
return false;
}
if (document.form1.title_suggestion.value.length < 1) {
alert("Please enter your suggestion title.");
return false;
}
if (document.form1.suggestion.value.length < 3) {
alert("Please enter your suggestion.");
return false;
}

return ture;
}
<<<snipped>>>>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4

P: n/a

Hi guys,
Thanks for your reply.
sorry about the confusion, here is the validating code.

with many thanks

<<<snipped>>>>

<script type="text/javascript">

//Validating the form

function validate(){
if (document.form1.f_name.value.length < 1) {
alert("Please enter your first name.");
return false;
}
if (document.form1.s_name.value.length < 1) {
alert("Please enter your surname.");
return false;
}
if (document.form1.e_address.value.length < 1) {
alert("Please enter your first name.");
return false;
}
if (document.form1.f_name.value.length < 1) {
alert("Please enter your emailaddress.");
return false;
}
if (document.form1.tel_number.value.length < 1) {
alert("Please enter your telephone number.");
return false;
}
if (document.form1.emp_id.value.length < 1) {
alert("Please enter your employee ID.");
return false;
}
if (document.form1.title_suggestion.value.length < 1) {
alert("Please enter your suggestion title.");
return false;
}
if (document.form1.suggestion.value.length < 3) {
alert("Please enter your suggestion.");
return false;
}

return ture;
}
<<<snipped>>>>


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5

P: n/a
JRS: In article <41**********@127.0.0.1>, dated Sun, 16 Jan 2005
08:50:26, seen in news:comp.lang.javascript, x muzuo
<mu******@yahoo.co.uk> posted :
return ture;


Quaint. Please post properly checked code, inserted by copy'n'paste.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6

P: n/a
"x muzuo" <mu******@yahoo.co.uk> wrote in message
news:41**********@127.0.0.1...
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.

Here is the code:
<input type="submit" value="Submit"
onclick="this.form.submit();this.disabled='true';t his.value='Please
Wait..';">
You are programmatically calling Form#submit() from a submit button!

Why would ever feel the need to do this, an <input type="submit" SUBMITS
THE FORM. You don't need to include ONCLICK="...submit the form...", it
ALREADY KNOWS HOW TO DO THAT.

Not only that, but programmatically calling Form#submit() does _not_
call the onsubmit event of the <form>, so your validation code _never
runs_.

<input type="submit" value="Submit"
onclick="this.value='Please wait...';this.disabled=true;return true;">

Please note that the -disabled- property takes a boolean, not a string.

By the way, if the user clicks Stop before the form gets navigated away
from, or the form submission fails for some reason, you've left the user
with a form that can not be re-submitted. One possible (but not
necessarily the correct) solution to this is:

<form name="myForm">
<input type="submit" name="mySubmit"
value="Submit"
onclick="
this.value='Please wait...';
this.disabled=true;
var t = setTimeout(
'(sub=document.forms[\'myForm\'].elements[\'mySubmit\']).disabled=false;sub.value=\'Submit\';',
5000
);
return false;
"

</form>

This restores the submit button to working state after 5 seconds.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.